Search in sources :

Example 91 with QueueChannel

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

the class AsyncMessagingTemplateTests method asyncReceiveAndConvertWithDefaultChannel.

@Test
public void asyncReceiveAndConvertWithDefaultChannel() throws Exception {
    QueueChannel channel = new QueueChannel();
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    template.setDefaultDestination(channel);
    Future<?> result = template.asyncReceiveAndConvert();
    sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200);
    long start = System.currentTimeMillis();
    assertNotNull(result.get(10000, TimeUnit.MILLISECONDS));
    long elapsed = System.currentTimeMillis() - start;
    assertEquals("test", result.get());
    assertTrue(elapsed >= 200 - safety);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 92 with QueueChannel

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

the class AsyncMessagingTemplateTests method asyncConvertAndSendWithResolvedChannel.

@Test
public void asyncConvertAndSendWithResolvedChannel() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerSingleton("testChannel", QueueChannel.class);
    context.refresh();
    QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    template.setBeanFactory(context);
    Future<?> future = template.asyncConvertAndSend("testChannel", "test");
    assertNull(future.get(10000, TimeUnit.MILLISECONDS));
    Message<?> result = channel.receive(0);
    assertEquals("test", result.getPayload());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Example 93 with QueueChannel

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

the class AsyncMessagingTemplateTests method asyncReceiveWithTimeoutException.

@Test(expected = TimeoutException.class)
public void asyncReceiveWithTimeoutException() throws Exception {
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    Future<Message<?>> result = template.asyncReceive(new QueueChannel());
    result.get(100, TimeUnit.MILLISECONDS);
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 94 with QueueChannel

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

the class AsyncMessagingTemplateTests method asyncConvertAndSendWithDefaultChannel.

@Test
public void asyncConvertAndSendWithDefaultChannel() throws Exception {
    QueueChannel channel = new QueueChannel();
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    template.setDefaultDestination(channel);
    Future<?> future = template.asyncConvertAndSend("test");
    assertNull(future.get(10000, TimeUnit.MILLISECONDS));
    Message<?> result = channel.receive(0);
    assertEquals("test", result.getPayload());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 95 with QueueChannel

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

the class CorrelationHandlerTests method testSplitterResequencer.

@Test
public void testSplitterResequencer() {
    QueueChannel replyChannel = new QueueChannel();
    this.splitInput.send(MessageBuilder.withPayload("").setReplyChannel(replyChannel).setHeader("foo", "bar").build());
    for (int i = 0; i < 12; i++) {
        Message<?> receive = replyChannel.receive(2000);
        assertNotNull(receive);
        assertFalse(receive.getHeaders().containsKey("foo"));
        assertTrue(receive.getHeaders().containsKey("FOO"));
        assertEquals("BAR", receive.getHeaders().get("FOO"));
        assertEquals(i + 1, 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