Search in sources :

Example 1 with UnicastingDispatcher

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;
}
Also used : RoundRobinLoadBalancingStrategy(org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy) UnicastingDispatcher(org.springframework.integration.dispatcher.UnicastingDispatcher)

Example 2 with 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));
}
Also used : UnicastingDispatcher(org.springframework.integration.dispatcher.UnicastingDispatcher) MessageRejectedException(org.springframework.integration.MessageRejectedException) Test(org.junit.Test)

Example 3 with UnicastingDispatcher

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);
}
Also used : RoundRobinLoadBalancingStrategy(org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy) InOrder(org.mockito.InOrder) UnicastingDispatcher(org.springframework.integration.dispatcher.UnicastingDispatcher) MessageRejectedException(org.springframework.integration.MessageRejectedException) MessageRejectedException(org.springframework.integration.MessageRejectedException) Test(org.junit.Test)

Example 4 with UnicastingDispatcher

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);
}
Also used : InOrder(org.mockito.InOrder) UnicastingDispatcher(org.springframework.integration.dispatcher.UnicastingDispatcher) MessageRejectedException(org.springframework.integration.MessageRejectedException) MessageRejectedException(org.springframework.integration.MessageRejectedException) Test(org.junit.Test)

Example 5 with UnicastingDispatcher

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"));
}
Also used : Set(java.util.Set) AbstractXmppConnectionAwareMessageHandler(org.springframework.integration.xmpp.core.AbstractXmppConnectionAwareMessageHandler) MessageHandler(org.springframework.messaging.MessageHandler) UnicastingDispatcher(org.springframework.integration.dispatcher.UnicastingDispatcher) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Aggregations

UnicastingDispatcher (org.springframework.integration.dispatcher.UnicastingDispatcher)14 Test (org.junit.Test)11 MessageRejectedException (org.springframework.integration.MessageRejectedException)8 RoundRobinLoadBalancingStrategy (org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 InOrder (org.mockito.InOrder)2 Set (java.util.Set)1 Log (org.apache.commons.logging.Log)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 BroadcastingDispatcher (org.springframework.integration.dispatcher.BroadcastingDispatcher)1 BeanFactoryChannelResolver (org.springframework.integration.support.channel.BeanFactoryChannelResolver)1 ErrorHandlingTaskExecutor (org.springframework.integration.util.ErrorHandlingTaskExecutor)1 AbstractXmppConnectionAwareMessageHandler (org.springframework.integration.xmpp.core.AbstractXmppConnectionAwareMessageHandler)1 MessageHandler (org.springframework.messaging.MessageHandler)1 SubscribableChannel (org.springframework.messaging.SubscribableChannel)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1 ErrorHandler (org.springframework.util.ErrorHandler)1