Search in sources :

Example 36 with QueueChannel

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

the class MethodInvokingRouterTests method channelNameResolutionByPayloadConfiguredByMethodReference.

@Test
public void channelNameResolutionByPayloadConfiguredByMethodReference() throws Exception {
    QueueChannel barChannel = new QueueChannel();
    TestChannelResolver channelResolver = new TestChannelResolver();
    channelResolver.addChannel("bar-channel", barChannel);
    SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean();
    Method routingMethod = testBean.getClass().getMethod("routePayload", String.class);
    MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod);
    router.setChannelResolver(channelResolver);
    Message<String> message = new GenericMessage<String>("bar");
    router.handleMessage(message);
    Message<?> replyMessage = barChannel.receive();
    assertNotNull(replyMessage);
    assertEquals(message, replyMessage);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) TestChannelResolver(org.springframework.integration.channel.TestChannelResolver) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 37 with QueueChannel

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

the class MethodInvokingRouterTests method doTestMultiChannelNameResolutionByPayload.

private void doTestMultiChannelNameResolutionByPayload(MethodInvokingRouter router, TestChannelResolver channelResolver) {
    QueueChannel fooChannel = new QueueChannel();
    QueueChannel barChannel = new QueueChannel();
    channelResolver.addChannel("foo-channel", fooChannel);
    channelResolver.addChannel("bar-channel", barChannel);
    router.setChannelResolver(channelResolver);
    Message<String> fooMessage = new GenericMessage<String>("foo");
    Message<String> barMessage = new GenericMessage<String>("bar");
    Message<String> badMessage = new GenericMessage<String>("bad");
    router.handleMessage(fooMessage);
    Message<?> result1a = fooChannel.receive(0);
    Message<?> result1b = barChannel.receive(0);
    assertNotNull(result1a);
    assertEquals("foo", result1a.getPayload());
    assertNotNull(result1b);
    assertEquals("foo", result1b.getPayload());
    router.handleMessage(barMessage);
    Message<?> result2a = fooChannel.receive(0);
    Message<?> result2b = barChannel.receive(0);
    assertNotNull(result2a);
    assertEquals("bar", result2a.getPayload());
    assertNotNull(result2b);
    assertEquals("bar", result2b.getPayload());
    try {
        router.handleMessage(badMessage);
        fail();
    } catch (MessageDeliveryException e) {
    /* Success */
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Example 38 with QueueChannel

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

the class PayloadTypeRouterTests method classLosesOverAmbiguousInterfacesAtSameLevel.

@Test(expected = MessageHandlingException.class)
public void classLosesOverAmbiguousInterfacesAtSameLevel() throws Exception {
    QueueChannel defaultChannel = new QueueChannel();
    defaultChannel.setBeanName("defaultChannel");
    QueueChannel i1aChannel = new QueueChannel();
    i1aChannel.setBeanName("i1aChannel");
    QueueChannel i1bChannel = new QueueChannel();
    i1bChannel.setBeanName("i1bChannel");
    QueueChannel c2Channel = new QueueChannel();
    c2Channel.setBeanName("c2Channel");
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerSingleton("defaultChannel", defaultChannel);
    beanFactory.registerSingleton("i1aChannel", i1aChannel);
    beanFactory.registerSingleton("i1bChannel", i1bChannel);
    beanFactory.registerSingleton("c2Channel", c2Channel);
    Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
    payloadTypeChannelMap.put(I1A.class.getName(), "i1aChannel");
    payloadTypeChannelMap.put(I1B.class.getName(), "i2bChannel");
    payloadTypeChannelMap.put(C2.class.getName(), "c2Channel");
    PayloadTypeRouter router = new PayloadTypeRouter();
    router.setBeanFactory(beanFactory);
    router.setChannelMappings(payloadTypeChannelMap);
    router.setDefaultOutputChannel(defaultChannel);
    Message<C1> message = new GenericMessage<C1>(new C1());
    router.handleMessage(message);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 39 with QueueChannel

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

the class PayloadTypeRouterTests method interfaceMatch.

@Test
public void interfaceMatch() {
    QueueChannel defaultChannel = new QueueChannel();
    defaultChannel.setBeanName("defaultChannel");
    QueueChannel comparableChannel = new QueueChannel();
    comparableChannel.setBeanName("comparableChannel");
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerSingleton("defaultChannel", defaultChannel);
    beanFactory.registerSingleton("comparableChannel", comparableChannel);
    Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
    payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
    PayloadTypeRouter router = new PayloadTypeRouter();
    router.setBeanFactory(beanFactory);
    router.setChannelMappings(payloadTypeChannelMap);
    router.setDefaultOutputChannel(defaultChannel);
    Message<Integer> message = new GenericMessage<Integer>(99);
    router.handleMessage(message);
    Message<?> result = comparableChannel.receive(0);
    assertNotNull(result);
    assertEquals(99, result.getPayload());
    assertNull(defaultChannel.receive(0));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 40 with QueueChannel

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

the class PayloadTypeRouterTests method directInterfaceOverTwoHopSuperclass.

@Test
public void directInterfaceOverTwoHopSuperclass() {
    QueueChannel defaultChannel = new QueueChannel();
    defaultChannel.setBeanName("defaultChannel");
    QueueChannel c3Channel = new QueueChannel();
    c3Channel.setBeanName("c3Channel");
    QueueChannel i1AChannel = new QueueChannel();
    i1AChannel.setBeanName("i1AChannel");
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerSingleton("defaultChannel", defaultChannel);
    beanFactory.registerSingleton("c3Channel", c3Channel);
    beanFactory.registerSingleton("i1AChannel", i1AChannel);
    Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
    payloadTypeChannelMap.put(C3.class.getName(), "c3Channel");
    payloadTypeChannelMap.put(I1A.class.getName(), "i1AChannel");
    PayloadTypeRouter router = new PayloadTypeRouter();
    router.setBeanFactory(beanFactory);
    router.setChannelMappings(payloadTypeChannelMap);
    router.setDefaultOutputChannel(defaultChannel);
    Message<C1> message = new GenericMessage<C1>(new C1());
    router.handleMessage(message);
    Message<?> result = i1AChannel.receive(0);
    assertNotNull(result);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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