Search in sources :

Example 41 with QueueChannel

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

the class PayloadTypeRouterTests method ambiguityFailure.

@Test(expected = MessageHandlingException.class)
public void ambiguityFailure() throws Exception {
    QueueChannel defaultChannel = new QueueChannel();
    defaultChannel.setBeanName("defaultChannel");
    QueueChannel serializableChannel = new QueueChannel();
    serializableChannel.setBeanName("serializableChannel");
    QueueChannel comparableChannel = new QueueChannel();
    comparableChannel.setBeanName("comparableChannel");
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerSingleton("defaultChannel", defaultChannel);
    beanFactory.registerSingleton("serializableChannel", serializableChannel);
    beanFactory.registerSingleton("comparableChannel", comparableChannel);
    Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
    payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel");
    payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
    PayloadTypeRouter router = new PayloadTypeRouter();
    router.setBeanFactory(beanFactory);
    router.setChannelMappings(payloadTypeChannelMap);
    router.setDefaultOutputChannel(defaultChannel);
    Message<String> message = new GenericMessage<String>("test");
    router.handleMessage(message);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Serializable(java.io.Serializable) QueueChannel(org.springframework.integration.channel.QueueChannel) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 42 with QueueChannel

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

the class PayloadTypeRouterTests method resolveByPayloadTypeWithRouterEndpoint.

@Test
public void resolveByPayloadTypeWithRouterEndpoint() {
    QueueChannel stringChannel = new QueueChannel();
    QueueChannel integerChannel = new QueueChannel();
    stringChannel.setBeanName("stringChannel");
    integerChannel.setBeanName("integerChannel");
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerSingleton("stringChannel", stringChannel);
    beanFactory.registerSingleton("integerChannel", integerChannel);
    Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
    payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
    payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
    PayloadTypeRouter router = new PayloadTypeRouter();
    router.setBeanFactory(beanFactory);
    router.setChannelMappings(payloadTypeChannelMap);
    Message<String> message1 = new GenericMessage<String>("test");
    Message<Integer> message2 = new GenericMessage<Integer>(123);
    router.handleMessage(message1);
    router.handleMessage(message2);
    Message<?> reply1 = stringChannel.receive(0);
    Message<?> reply2 = integerChannel.receive(0);
    assertEquals("test", reply1.getPayload());
    assertEquals(123, reply2.getPayload());
}
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 43 with QueueChannel

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

the class PayloadTypeRouterTests method exactMatchFavoredOverSuperclass.

@Test
public void exactMatchFavoredOverSuperclass() {
    QueueChannel defaultChannel = new QueueChannel();
    defaultChannel.setBeanName("defaultChannel");
    QueueChannel numberChannel = new QueueChannel();
    numberChannel.setBeanName("numberChannel");
    QueueChannel integerChannel = new QueueChannel();
    integerChannel.setBeanName("integerChannel");
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerSingleton("defaultChannel", defaultChannel);
    beanFactory.registerSingleton("numberChannel", numberChannel);
    beanFactory.registerSingleton("integerChannel", integerChannel);
    Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
    payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
    payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
    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 = integerChannel.receive(0);
    assertNotNull(result);
    assertEquals(99, result.getPayload());
    assertNull(numberChannel.receive(0));
    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 44 with QueueChannel

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

the class PayloadTypeRouterTests method directInterfaceFavoredOverSuperclass.

@Test
public void directInterfaceFavoredOverSuperclass() {
    QueueChannel defaultChannel = new QueueChannel();
    defaultChannel.setBeanName("defaultChannel");
    QueueChannel numberChannel = new QueueChannel();
    numberChannel.setBeanName("numberChannel");
    QueueChannel comparableChannel = new QueueChannel();
    comparableChannel.setBeanName("comparableChannel");
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerSingleton("defaultChannel", defaultChannel);
    beanFactory.registerSingleton("numberChannel", numberChannel);
    beanFactory.registerSingleton("comparableChannel", comparableChannel);
    Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
    payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
    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(numberChannel.receive(0));
    assertNull(defaultChannel.receive(0));
    // validate dynamics
    QueueChannel newChannel = new QueueChannel();
    beanFactory.registerSingleton("newChannel", newChannel);
    router.setChannelMapping(Integer.class.getName(), "newChannel");
    assertEquals(1, router.getChannelKeys(message).size());
    router.handleMessage(message);
    result = newChannel.receive(10);
    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)

Example 45 with QueueChannel

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

the class PayloadTypeRouterTests method classWinsOverMoreDistantAmbiguousInterfaces.

@Test
public void classWinsOverMoreDistantAmbiguousInterfaces() throws Exception {
    QueueChannel defaultChannel = new QueueChannel();
    defaultChannel.setBeanName("defaultChannel");
    QueueChannel i5aChannel = new QueueChannel();
    i5aChannel.setBeanName("i5aChannel");
    QueueChannel i5bChannel = new QueueChannel();
    i5bChannel.setBeanName("i5bChannel");
    QueueChannel c2Channel = new QueueChannel();
    c2Channel.setBeanName("c2Channel");
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerSingleton("defaultChannel", defaultChannel);
    beanFactory.registerSingleton("i5aChannel", i5aChannel);
    beanFactory.registerSingleton("i5bChannel", i5bChannel);
    beanFactory.registerSingleton("c2Channel", c2Channel);
    Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
    payloadTypeChannelMap.put(I5A.class.getName(), "i5aChannel");
    payloadTypeChannelMap.put(I5B.class.getName(), "i5bChannel");
    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);
    assertNotNull(c2Channel.receive(100));
}
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