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);
}
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 */
}
}
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);
}
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));
}
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);
}
Aggregations