use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.
the class JmsInboundChannelAdapterParserTests method messageDrivenAdapterWithMessageConverter.
@Test
public void messageDrivenAdapterWithMessageConverter() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsInboundWithMessageConverter.xml", this.getClass());
PollableChannel output = (PollableChannel) context.getBean("output2");
Message<?> message = output.receive(timeoutOnReceive);
assertNotNull("message should not be null", message);
assertEquals("converted-test", message.getPayload());
context.close();
}
use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.
the class JmsMessageDrivenChannelAdapterParserTests method adapterWithMessageSelector.
@Test
public void adapterWithMessageSelector() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsInboundWithMessageSelector.xml", this.getClass());
PollableChannel output = (PollableChannel) context.getBean("output2");
Message<?> message = output.receive(timeoutOnReceive);
MessageHistory history = MessageHistory.read(message);
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "messageDrivenAdapter", 0);
assertNotNull(componentHistoryRecord);
JmsMessageDrivenEndpoint endpoint = context.getBean("messageDrivenAdapter", JmsMessageDrivenEndpoint.class);
assertEquals("jms:message-driven-channel-adapter", componentHistoryRecord.get("type"));
assertNotNull("message should not be null", message);
assertEquals("test [with selector: TestProperty = 'foo']", message.getPayload());
endpoint.stop();
context.close();
}
use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.
the class JmsTests method testJmsPipelineFlow.
@Test
public void testJmsPipelineFlow() {
assertEquals(new Long(10000), TestUtils.getPropertyValue(this.jmsOutboundGatewayHandler, "idleReplyContainerTimeout", Long.class));
PollableChannel replyChannel = new QueueChannel();
Message<String> message = MessageBuilder.withPayload("hello through the jms pipeline").setReplyChannel(replyChannel).setHeader("destination", "jmsPipelineTest").build();
this.jmsOutboundGatewayChannel.send(message);
Message<?> receive = replyChannel.receive(5000);
assertNotNull(receive);
assertEquals("HELLO THROUGH THE JMS PIPELINE", receive.getPayload());
assertTrue(this.jmsInboundGatewayChannelCalled.get());
}
use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.
the class DelayerHandlerRescheduleIntegrationTests method testDelayerHandlerRescheduleWithMongoDbMessageStore.
@SuppressWarnings("unchecked")
private void testDelayerHandlerRescheduleWithMongoDbMessageStore(String config) throws Exception {
AbstractApplicationContext context = new ClassPathXmlApplicationContext(config, this.getClass());
MessageChannel input = context.getBean("input", MessageChannel.class);
MessageGroupStore messageStore = context.getBean("messageStore", MessageGroupStore.class);
String delayerMessageGroupId = DELAYER_ID + ".messageGroupId";
messageStore.removeMessageGroup(delayerMessageGroupId);
Message<String> message1 = MessageBuilder.withPayload("test1").build();
input.send(message1);
input.send(MessageBuilder.withPayload("test2").build());
// Emulate restart and check DB state before next start
// Interrupt taskScheduler as quickly as possible
ThreadPoolTaskScheduler taskScheduler = (ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context);
taskScheduler.shutdown();
taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS);
assertEquals(2, messageStore.messageGroupSize(delayerMessageGroupId));
MessageGroup messageGroup = messageStore.getMessageGroup(delayerMessageGroupId);
Iterator<Message<?>> iterator = messageGroup.getMessages().iterator();
Message<?> messageInStore = iterator.next();
Object payload = messageInStore.getPayload();
// INT-3049
assertTrue(payload instanceof DelayHandler.DelayedMessageWrapper);
Message<String> original1 = (Message<String>) ((DelayHandler.DelayedMessageWrapper) payload).getOriginal();
messageInStore = iterator.next();
Message<String> original2 = (Message<String>) ((DelayHandler.DelayedMessageWrapper) messageInStore.getPayload()).getOriginal();
assertThat(message1, Matchers.anyOf(Matchers.is(original1), Matchers.is(original2)));
context.close();
context.refresh();
PollableChannel output = context.getBean("output", PollableChannel.class);
Message<?> message = output.receive(20000);
assertNotNull(message);
Object payload1 = message.getPayload();
message = output.receive(20000);
assertNotNull(message);
Object payload2 = message.getPayload();
assertNotSame(payload1, payload2);
messageStore = context.getBean("messageStore", MessageGroupStore.class);
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
context.close();
}
use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.
the class HeaderValueRouterParserTests method testHeaderValuesAsChannels.
@Test
public void testHeaderValuesAsChannels() {
context.start();
MessageBuilder<?> channel1MessageBuilder = MessageBuilder.withPayload("");
channel1MessageBuilder.setHeader("testHeader", "channel1");
Message<?> message1 = channel1MessageBuilder.build();
MessageBuilder<?> channel2MessageBuilder = MessageBuilder.withPayload("");
channel2MessageBuilder.setHeader("testHeader", "channel2");
Message<?> message2 = channel2MessageBuilder.build();
testServiceA.foo(message1);
testServiceA.foo(message2);
PollableChannel channel1 = (PollableChannel) context.getBean("channel1");
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
message1 = channel1.receive();
assertTrue(message1.getHeaders().get("testHeader").equals("channel1"));
message2 = channel2.receive();
assertTrue(message2.getHeaders().get("testHeader").equals("channel2"));
}
Aggregations