Search in sources :

Example 86 with QueueChannel

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

the class EnableIntegrationTests method testSourcePollingChannelAdapterOutputChannelLateBinding.

@Test
public void testSourcePollingChannelAdapterOutputChannelLateBinding() {
    QueueChannel testChannel = new QueueChannel();
    ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) this.context.getAutowireCapableBeanFactory();
    beanFactory.registerSingleton("lateBindingChannel", testChannel);
    beanFactory.initializeBean(testChannel, "lateBindingChannel");
    this.autoCreatedChannelMessageSourceAdapter.start();
    Message<?> receive = testChannel.receive(10000);
    assertNotNull(receive);
    assertEquals("bar", receive.getPayload());
    this.autoCreatedChannelMessageSourceAdapter.stop();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.Test)

Example 87 with QueueChannel

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

the class AsyncMessagingTemplateTests method asyncReceiveAndConvertWithResolvedChannel.

@Test
public void asyncReceiveAndConvertWithResolvedChannel() 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<?> result = template.asyncReceiveAndConvert("testChannel");
    sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200);
    long start = System.currentTimeMillis();
    assertNotNull(result.get(10000, TimeUnit.MILLISECONDS));
    long elapsed = System.currentTimeMillis() - start;
    assertTrue(elapsed >= 200 - safety);
    assertEquals("test", result.get());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Example 88 with QueueChannel

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

the class AsyncMessagingTemplateTests method asyncSendWithExplicitChannel.

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

Example 89 with QueueChannel

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

the class AsyncMessagingTemplateTests method asyncSendWithTimeoutException.

@Test(expected = TimeoutException.class)
public void asyncSendWithTimeoutException() throws Exception {
    QueueChannel channel = new QueueChannel(1);
    channel.send(MessageBuilder.withPayload("blocker").build());
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    Future<?> result = template.asyncSend(channel, MessageBuilder.withPayload("test").build());
    result.get(100, TimeUnit.MILLISECONDS);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 90 with QueueChannel

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

the class AsyncMessagingTemplateTests method asyncSendWithDefaultChannel.

@Test
public void asyncSendWithDefaultChannel() throws Exception {
    QueueChannel channel = new QueueChannel();
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    template.setDefaultDestination(channel);
    Message<?> message = MessageBuilder.withPayload("test").build();
    Future<?> future = template.asyncSend(message);
    assertNull(future.get(10000, TimeUnit.MILLISECONDS));
    Message<?> result = channel.receive(0);
    assertEquals(message, result);
}
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