use of org.springframework.integration.dispatcher.UnicastingDispatcher in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method failoverNoLoadBalancingConcurrent.
@Test
public void failoverNoLoadBalancingConcurrent() throws Exception {
final 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);
dispatcher.addHandler(handlerC);
final CountDownLatch start = new CountDownLatch(1);
final CountDownLatch allDone = new CountDownLatch(TOTAL_EXECUTIONS);
final Message<?> message = this.message;
final AtomicBoolean failed = new AtomicBoolean(false);
Runnable messageSenderTask = () -> {
try {
start.await();
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
boolean sent = false;
try {
sent = channel.send(message);
} catch (Exception e2) {
exceptionRegistry.add(e2);
}
if (!sent) {
failed.set(true);
}
allDone.countDown();
};
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);
assertFalse("not all messages were accepted", failed.get());
verify(handlerA, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerB, times(TOTAL_EXECUTIONS)).handleMessage(message);
verify(handlerC, never()).handleMessage(message);
verify(exceptionRegistry, never()).add(any(Exception.class));
}
use of org.springframework.integration.dispatcher.UnicastingDispatcher in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method noFailoverLoadBalancingConcurrent.
@Test
public void noFailoverLoadBalancingConcurrent() throws Exception {
final DirectChannel channel = (DirectChannel) ac.getBean("loadBalancerNoFailover");
doThrow(new MessageRejectedException(message, null)).when(handlerA).handleMessage(message);
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
dispatcher.addHandler(handlerC);
final CountDownLatch start = new CountDownLatch(1);
final CountDownLatch allDone = new CountDownLatch(TOTAL_EXECUTIONS);
final Message<?> message = this.message;
final AtomicBoolean failed = new AtomicBoolean(false);
Runnable messageSenderTask = () -> {
try {
start.await();
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
boolean sent = false;
try {
sent = channel.send(message);
} catch (Exception e2) {
exceptionRegistry.add(e2);
}
if (!sent) {
failed.set(true);
}
allDone.countDown();
};
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(14)).handleMessage(message);
verify(handlerB, times(13)).handleMessage(message);
verify(handlerC, times(13)).handleMessage(message);
verify(exceptionRegistry, times(14)).add(any(Exception.class));
}
use of org.springframework.integration.dispatcher.UnicastingDispatcher in project spring-integration by spring-projects.
the class MixedDispatcherConfigurationScenarioTests method noFailoverNoLoadBalancing.
@Test
public void noFailoverNoLoadBalancing() {
DirectChannel channel = (DirectChannel) ac.getBean("noLoadBalancerNoFailover");
doThrow(new MessageRejectedException(message, null)).when(handlerA).handleMessage(message);
UnicastingDispatcher dispatcher = channel.getDispatcher();
dispatcher.addHandler(handlerA);
dispatcher.addHandler(handlerB);
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
try {
channel.send(message);
} catch (Exception e) {
/* ignore */
}
verify(handlerA, times(2)).handleMessage(message);
verify(handlerB, times(0)).handleMessage(message);
}
use of org.springframework.integration.dispatcher.UnicastingDispatcher in project spring-integration by spring-projects.
the class SubscribableJmsChannel method configureDispatcher.
private void configureDispatcher(boolean isPubSub) {
if (isPubSub) {
BroadcastingDispatcher broadcastingDispatcher = new BroadcastingDispatcher(true);
broadcastingDispatcher.setBeanFactory(this.getBeanFactory());
this.dispatcher = broadcastingDispatcher;
} else {
UnicastingDispatcher unicastingDispatcher = new UnicastingDispatcher();
unicastingDispatcher.setLoadBalancingStrategy(new RoundRobinLoadBalancingStrategy());
this.dispatcher = unicastingDispatcher;
}
if (this.maxSubscribers == null) {
this.maxSubscribers = this.getIntegrationProperty(isPubSub ? IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS : IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, Integer.class);
}
this.dispatcher.setMaxSubscribers(this.maxSubscribers);
}
Aggregations