use of org.springframework.integration.dispatcher.UnicastingDispatcher in project spring-integration by spring-projects.
the class PointToPointSubscribableAmqpChannel method createDispatcher.
@Override
protected AbstractDispatcher createDispatcher() {
UnicastingDispatcher unicastingDispatcher = new UnicastingDispatcher();
unicastingDispatcher.setLoadBalancingStrategy(new RoundRobinLoadBalancingStrategy());
return unicastingDispatcher;
}
use of org.springframework.integration.dispatcher.UnicastingDispatcher in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method noFailoverNoLoadBalancingWithExecutorConcurrent.
@Test
public void noFailoverNoLoadBalancingWithExecutorConcurrent() throws Exception {
final ExecutorChannel channel = (ExecutorChannel) ac.getBean("noLoadBalancerNoFailoverExecutor");
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
doAnswer(invocation -> {
RuntimeException e = new RuntimeException();
allDone.countDown();
failed.set(true);
exceptionRegistry.add(e);
throw e;
}).when(handlerA).handleMessage(message);
Runnable messageSenderTask = () -> {
try {
start.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
channel.send(message);
};
for (int i = 0; i < TOTAL_EXECUTIONS; i++) {
executor.execute(messageSenderTask);
}
start.countDown();
assertTrue(allDone.await(10, TimeUnit.SECONDS));
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
assertTrue("not all messages were accepted", failed.get());
verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerB, times(0)).handleMessage(message);
verify(exceptionRegistry, times(TOTAL_EXECUTIONS)).add(any(Exception.class));
}
use of org.springframework.integration.dispatcher.UnicastingDispatcher in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method noFailoverLoadBalancing.
@Test
public void noFailoverLoadBalancing() {
DirectChannel channel = (DirectChannel) ac.getBean("loadBalancerNoFailover");
doThrow(new MessageRejectedException(message, null)).when(handlerA).handleMessage(message);
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.setLoadBalancingStrategy(new RoundRobinLoadBalancingStrategy());
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
dispatcher.addHandler(handlerC);
InOrder inOrder = inOrder(handlerA, handlerB, handlerC);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerA).handleMessage(message);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerB).handleMessage(message);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerC).handleMessage(message);
verify(handlerA, times(1)).handleMessage(message);
verify(handlerB, times(1)).handleMessage(message);
verify(handlerC, times(1)).handleMessage(message);
}
use of org.springframework.integration.dispatcher.UnicastingDispatcher in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method failoverNoLoadBalancing.
@Test
public void failoverNoLoadBalancing() {
DirectChannel channel = (DirectChannel) ac.getBean("noLoadBalancerFailover");
doThrow(new MessageRejectedException(message, null)).when(handlerA).handleMessage(message);
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
InOrder inOrder = inOrder(handlerA, handlerB);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerA).handleMessage(message);
inOrder.verify(handlerB).handleMessage(message);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
inOrder.verify(handlerA).handleMessage(message);
inOrder.verify(handlerB).handleMessage(message);
verify(handlerA, times(2)).handleMessage(message);
verify(handlerB, times(2)).handleMessage(message);
}
use of org.springframework.integration.dispatcher.UnicastingDispatcher in project spring-integration by spring-projects.
the class PresenceOutboundChannelAdapterParserTests method testRosterEventOutboundChannel.
@Test
public void testRosterEventOutboundChannel() {
Object channel = context.getBean("eventOutboundRosterChannel");
assertTrue(channel instanceof SubscribableChannel);
UnicastingDispatcher dispatcher = (UnicastingDispatcher) TestUtils.getPropertyValue(channel, "dispatcher");
@SuppressWarnings("unchecked") Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils.getPropertyValue(dispatcher, "handlers");
assertEquals(45, TestUtils.getPropertyValue(handlers.toArray()[0], "order"));
}
Aggregations