Search in sources :

Example 6 with BroadcastingDispatcher

use of org.springframework.integration.dispatcher.BroadcastingDispatcher in project spring-integration by spring-projects.

the class PublishSubscribeChannelParserTests method defaultChannel.

@Test
public void defaultChannel() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("defaultChannel");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    dispatcher.setApplySequence(true);
    dispatcher.addHandler(message -> {
    });
    dispatcher.dispatch(new GenericMessage<String>("foo"));
    DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
    assertNull(dispatcherAccessor.getPropertyValue("executor"));
    assertFalse((Boolean) dispatcherAccessor.getPropertyValue("ignoreFailures"));
    assertTrue((Boolean) dispatcherAccessor.getPropertyValue("applySequence"));
    Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
    assertSame(mbf, dispatcherAccessor.getPropertyValue("messageBuilderFactory"));
    context.close();
}
Also used : PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher) Test(org.junit.Test)

Example 7 with BroadcastingDispatcher

use of org.springframework.integration.dispatcher.BroadcastingDispatcher in project spring-integration by spring-projects.

the class PublishSubscribeChannelParserTests method channelWithTaskExecutor.

@Test
public void channelWithTaskExecutor() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithTaskExecutor");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
    Executor executor = (Executor) dispatcherAccessor.getPropertyValue("executor");
    assertNotNull(executor);
    assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
    DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
    Executor innerExecutor = (Executor) executorAccessor.getPropertyValue("executor");
    assertEquals(context.getBean("pool"), innerExecutor);
    context.close();
}
Also used : ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor) Executor(java.util.concurrent.Executor) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher) Test(org.junit.Test)

Example 8 with BroadcastingDispatcher

use of org.springframework.integration.dispatcher.BroadcastingDispatcher in project spring-integration by spring-projects.

the class PublishSubscribeChannelParserTests method applySequenceEnabled.

@Test
public void applySequenceEnabled() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithApplySequenceEnabled");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    assertTrue((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("applySequence"));
    context.close();
}
Also used : PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher) Test(org.junit.Test)

Example 9 with BroadcastingDispatcher

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

Aggregations

BroadcastingDispatcher (org.springframework.integration.dispatcher.BroadcastingDispatcher)9 Test (org.junit.Test)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 PublishSubscribeChannel (org.springframework.integration.channel.PublishSubscribeChannel)6 ErrorHandlingTaskExecutor (org.springframework.integration.util.ErrorHandlingTaskExecutor)4 Executor (java.util.concurrent.Executor)3 RoundRobinLoadBalancingStrategy (org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy)1 UnicastingDispatcher (org.springframework.integration.dispatcher.UnicastingDispatcher)1 BeanFactoryChannelResolver (org.springframework.integration.support.channel.BeanFactoryChannelResolver)1