Search in sources :

Example 96 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class FlowServiceTests method testGatewayExplicitReplyChannel.

@Test
public void testGatewayExplicitReplyChannel() {
    QueueChannel replyChannel = new QueueChannel();
    this.testGatewayInput.send(MessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build());
    Message<?> message = replyChannel.receive(10000);
    assertNotNull(message);
    assertEquals("FOO", message.getPayload());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 97 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class FilterAnnotationMethodResolutionTests method resolveAnnotatedMethod.

@Test
public void resolveAnnotatedMethod() throws Exception {
    TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    FilterFactoryBean factoryBean = new FilterFactoryBean();
    factoryBean.setBeanFactory(testApplicationContext);
    AnnotatedTestFilter filter = new AnnotatedTestFilter();
    factoryBean.setTargetObject(filter);
    MessageHandler handler = factoryBean.getObject();
    QueueChannel replyChannel = new QueueChannel();
    handler.handleMessage(MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build());
    Message<?> result = replyChannel.receive(0);
    assertNotNull(result);
    assertTrue(filter.invokedCorrectMethod);
    assertFalse(filter.invokedIncorrectMethod);
    testApplicationContext.close();
}
Also used : TestUtils(org.springframework.integration.test.util.TestUtils) MessageHandler(org.springframework.messaging.MessageHandler) QueueChannel(org.springframework.integration.channel.QueueChannel) FilterFactoryBean(org.springframework.integration.config.FilterFactoryBean) Test(org.junit.Test)

Example 98 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class MessageFilterTests method filterThrowsException.

@Test(expected = MessageRejectedException.class)
public void filterThrowsException() {
    MessageFilter filter = new MessageFilter(message -> false);
    filter.setThrowExceptionOnRejection(true);
    QueueChannel output = new QueueChannel();
    filter.setOutputChannel(output);
    filter.handleMessage(new GenericMessage<String>("test"));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 99 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class MessageFilterTests method filterAcceptsWithChannels.

@Test
public void filterAcceptsWithChannels() {
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    MessageFilter filter = new MessageFilter(message -> true);
    filter.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
    endpoint.start();
    Message<?> message = new GenericMessage<String>("test");
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertNotNull(reply);
    assertEquals(message.getPayload(), reply.getPayload());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 100 with QueueChannel

use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.

the class MessageFilterTests method filterAcceptsMessage.

@Test
public void filterAcceptsMessage() {
    MessageFilter filter = new MessageFilter(message -> true);
    Message<?> message = new GenericMessage<String>("test");
    QueueChannel output = new QueueChannel();
    filter.setOutputChannel(output);
    filter.handleMessage(message);
    Message<?> received = output.receive(0);
    assertEquals(message.getPayload(), received.getPayload());
    assertEquals(message.getHeaders().getId(), received.getHeaders().getId());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Aggregations

QueueChannel (org.springframework.integration.channel.QueueChannel)709 Test (org.junit.Test)669 GenericMessage (org.springframework.messaging.support.GenericMessage)186 Message (org.springframework.messaging.Message)173 BeanFactory (org.springframework.beans.factory.BeanFactory)162 MessageChannel (org.springframework.messaging.MessageChannel)100 Matchers.containsString (org.hamcrest.Matchers.containsString)66 CountDownLatch (java.util.concurrent.CountDownLatch)59 DirectChannel (org.springframework.integration.channel.DirectChannel)57 ArrayList (java.util.ArrayList)55 PollableChannel (org.springframework.messaging.PollableChannel)55 MessagingException (org.springframework.messaging.MessagingException)53 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)51 AtomicReference (java.util.concurrent.atomic.AtomicReference)47 Socket (java.net.Socket)44 ErrorMessage (org.springframework.messaging.support.ErrorMessage)42 ServerSocket (java.net.ServerSocket)41 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)39 IOException (java.io.IOException)35 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)35