Search in sources :

Example 56 with QueueChannel

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

the class MethodInvokingMessageHandlerTests method subscription.

@Test
public void subscription() throws Exception {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    SynchronousQueue<String> queue = new SynchronousQueue<String>();
    TestBean testBean = new TestBean(queue);
    QueueChannel channel = new QueueChannel();
    context.registerChannel("channel", channel);
    Message<String> message = new GenericMessage<String>("testing");
    channel.send(message);
    assertNull(queue.poll());
    MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(testBean, "foo");
    PollingConsumer endpoint = new PollingConsumer(channel, handler);
    endpoint.setTrigger(new PeriodicTrigger(10));
    context.registerEndpoint("testEndpoint", endpoint);
    context.refresh();
    String result = queue.poll(2000, TimeUnit.MILLISECONDS);
    assertNotNull(result);
    assertEquals("testing", result);
    context.stop();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MethodInvokingMessageHandler(org.springframework.integration.handler.MethodInvokingMessageHandler) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) SynchronousQueue(java.util.concurrent.SynchronousQueue) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Test(org.junit.Test)

Example 57 with QueueChannel

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

the class CustomConverterMessageProcessingTests method serviceActivator.

@Test
public void serviceActivator() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload(new TestBean1("service-test")).setReplyChannel(replyChannel).build();
    this.serviceActivatorChannel.send(message);
    Message<?> result = replyChannel.receive(0);
    assertNotNull(result);
    assertNotNull(result.getPayload());
    assertEquals(TestBean2.class, result.getPayload().getClass());
    assertEquals("SERVICE-TEST", ((TestBean2) result.getPayload()).text);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 58 with QueueChannel

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

the class CustomConverterMessageProcessingTests method splitter.

@Test
public void splitter() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload(new TestBean1("splitter-test")).setReplyChannel(replyChannel).build();
    this.splitterChannel.send(message);
    Message<?> result = replyChannel.receive(0);
    assertNotNull(result);
    assertNotNull(result.getPayload());
    assertEquals(TestBean2.class, result.getPayload().getClass());
    assertEquals("SPLITTER-TEST", ((TestBean2) result.getPayload()).text);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 59 with QueueChannel

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

the class CustomConverterMessageProcessingTests method filter.

@Test
public void filter() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload(new TestBean1("filter-test")).setReplyChannel(replyChannel).build();
    this.filterChannel.send(message);
    Message<?> result = replyChannel.receive(0);
    assertNotNull(result);
    assertNotNull(result.getPayload());
    assertEquals(TestBean1.class, result.getPayload().getClass());
    assertEquals("filter-test", ((TestBean1) result.getPayload()).text);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 60 with QueueChannel

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

the class JsonPathTests method testJsonPathOnPayloadAnnotation.

@Test
public void testJsonPathOnPayloadAnnotation() {
    QueueChannel replyChannel = new QueueChannel();
    Message<String> message = MessageBuilder.withPayload(JSON).setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build();
    this.jsonPathMessageChannel.send(message);
    Message<?> receive = replyChannel.receive(10_000);
    assertNotNull(receive);
    assertEquals("Nigel Rees", receive.getPayload());
}
Also used : 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