Search in sources :

Example 41 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class HeaderEnricherTests method errorChannel.

@Test
public void errorChannel() {
    PollableChannel errorChannel = context.getBean("testErrorChannel", PollableChannel.class);
    MessageChannel inputChannel = context.getBean("errorChannelInput", MessageChannel.class);
    inputChannel.send(new GenericMessage<String>("test"));
    Message<?> errorMessage = errorChannel.receive(1000);
    assertNotNull(errorMessage);
    Object errorPayload = errorMessage.getPayload();
    assertEquals(MessageTransformationException.class, errorPayload.getClass());
    Message<?> failedMessage = ((MessageTransformationException) errorPayload).getFailedMessage();
    assertEquals("test", failedMessage.getPayload());
    assertEquals(errorChannel, failedMessage.getHeaders().getErrorChannel());
}
Also used : MessageTransformationException(org.springframework.integration.transformer.MessageTransformationException) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 42 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class MessagingAnnotationPostProcessorTests method serviceActivatorInApplicationContext.

@Test
public void serviceActivatorInApplicationContext() throws Exception {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("serviceActivatorAnnotationPostProcessorTests.xml", this.getClass());
    MessageChannel inputChannel = (MessageChannel) context.getBean("inputChannel");
    PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
    inputChannel.send(new GenericMessage<String>("world"));
    Message<?> reply = outputChannel.receive(0);
    assertEquals("hello world", reply.getPayload());
    context.close();
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 43 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class InnerDefinitionHandlerAwareEndpointParserTests method testAggregatorDefinitionSuccess.

private void testAggregatorDefinitionSuccess(String configProperty) {
    ApplicationContext ac = this.bootStrap(configProperty);
    MessageChannel inChannel = (MessageChannel) ac.getBean("inChannel");
    for (int i = 0; i < 5; i++) {
        Map<String, Object> headers = stubHeaders(i, 5, 1);
        Message<Integer> message = MessageBuilder.withPayload(i).copyHeaders(headers).build();
        inChannel.send(message);
    }
    PollableChannel output = (PollableChannel) ac.getBean("outChannel");
    Message<?> receivedMessage = output.receive(10000);
    assertNotNull(receivedMessage);
    assertEquals(0 + 1 + 2 + 3 + 4, receivedMessage.getPayload());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel)

Example 44 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class InnerDefinitionHandlerAwareEndpointParserTests method testSplitterDefinitionSuccess.

private void testSplitterDefinitionSuccess(String configProperty) {
    ApplicationContext ac = this.bootStrap(configProperty);
    EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testSplitter");
    Assert.assertNotNull(splitter);
    MessageBuilder<String[]> inChannelMessageBuilder = MessageBuilder.withPayload(new String[] { "One", "Two" });
    Message<String[]> inMessage = inChannelMessageBuilder.build();
    MessageChannel inChannel = (MessageChannel) ac.getBean("inChannel");
    inChannel.send(inMessage);
    PollableChannel outChannel = (PollableChannel) ac.getBean("outChannel");
    Assert.assertTrue(outChannel.receive().getPayload() instanceof String);
    outChannel = (PollableChannel) ac.getBean("outChannel");
    Assert.assertTrue(outChannel.receive().getPayload() instanceof String);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel)

Example 45 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class InnerDefinitionHandlerAwareEndpointParserTests method testRouterDefinitionSuccess.

private void testRouterDefinitionSuccess(String configProperty) {
    ApplicationContext ac = this.bootStrap(configProperty);
    EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testRouter");
    Assert.assertNotNull(splitter);
    MessageBuilder<String> inChannelMessageBuilder = MessageBuilder.withPayload("1");
    Message<String> inMessage = inChannelMessageBuilder.build();
    DirectChannel inChannel = (DirectChannel) ac.getBean("inChannel");
    inChannel.send(inMessage);
    PollableChannel channel1 = (PollableChannel) ac.getBean("channel1");
    Assert.assertTrue(channel1.receive().getPayload().equals("1"));
    inChannelMessageBuilder = MessageBuilder.withPayload("2");
    inMessage = inChannelMessageBuilder.build();
    inChannel.send(inMessage);
    PollableChannel channel2 = (PollableChannel) ac.getBean("channel2");
    Assert.assertTrue(channel2.receive().getPayload().equals("2"));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) PollableChannel(org.springframework.messaging.PollableChannel)

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