Search in sources :

Example 71 with PollableChannel

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();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 72 with PollableChannel

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();
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Properties(java.util.Properties) JmsMessageDrivenEndpoint(org.springframework.integration.jms.JmsMessageDrivenEndpoint) Test(org.junit.Test)

Example 73 with PollableChannel

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());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 74 with PollableChannel

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();
}
Also used : DelayHandler(org.springframework.integration.handler.DelayHandler) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) Message(org.springframework.messaging.Message) MessageGroup(org.springframework.integration.store.MessageGroup) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel)

Example 75 with PollableChannel

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"));
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Aggregations

PollableChannel (org.springframework.messaging.PollableChannel)210 Test (org.junit.Test)190 MessageChannel (org.springframework.messaging.MessageChannel)89 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)82 QueueChannel (org.springframework.integration.channel.QueueChannel)52 GenericMessage (org.springframework.messaging.support.GenericMessage)52 Message (org.springframework.messaging.Message)40 BeanFactory (org.springframework.beans.factory.BeanFactory)25 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)20 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)19 MessagingException (org.springframework.messaging.MessagingException)16 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)13 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)12 ErrorMessage (org.springframework.messaging.support.ErrorMessage)12 Document (org.w3c.dom.Document)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 MessageHistory (org.springframework.integration.history.MessageHistory)9