Search in sources :

Example 1 with BroadcastingDispatcher

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

the class PublishSubscribeAmqpChannel method createDispatcher.

@Override
protected AbstractDispatcher createDispatcher() {
    BroadcastingDispatcher broadcastingDispatcher = new BroadcastingDispatcher(true);
    broadcastingDispatcher.setBeanFactory(this.getBeanFactory());
    return broadcastingDispatcher;
}
Also used : BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher)

Example 2 with BroadcastingDispatcher

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

the class PublishSubscribeChannelParserTests method applySequenceEnabledWithTaskExecutor.

@Test
public void applySequenceEnabledWithTaskExecutor() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithApplySequenceEnabledAndTaskExecutor");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
    assertTrue((Boolean) dispatcherAccessor.getPropertyValue("applySequence"));
    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 3 with BroadcastingDispatcher

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

the class PublishSubscribeChannel method onInit.

/**
 * Callback method for initialization.
 * @throws Exception the exception.
 */
@Override
public final void onInit() throws Exception {
    super.onInit();
    if (this.executor != null) {
        Assert.state(getDispatcher().getHandlerCount() == 0, "When providing an Executor, you cannot subscribe() until the channel " + "bean is fully initialized by the framework. Do not subscribe in a @Bean definition");
        if (!(this.executor instanceof ErrorHandlingTaskExecutor)) {
            if (this.errorHandler == null) {
                this.errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(this.getBeanFactory()));
            }
            this.executor = new ErrorHandlingTaskExecutor(this.executor, this.errorHandler);
        }
        this.dispatcher = new BroadcastingDispatcher(this.executor);
        getDispatcher().setIgnoreFailures(this.ignoreFailures);
        getDispatcher().setApplySequence(this.applySequence);
        getDispatcher().setMinSubscribers(this.minSubscribers);
    }
    if (this.maxSubscribers == null) {
        Integer maxSubscribers = getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS, Integer.class);
        this.setMaxSubscribers(maxSubscribers);
    }
    getDispatcher().setBeanFactory(this.getBeanFactory());
    getDispatcher().setMessageHandlingTaskDecorator(task -> {
        if (PublishSubscribeChannel.this.executorInterceptorsSize > 0) {
            return new MessageHandlingTask(task);
        } else {
            return task;
        }
    });
}
Also used : BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher)

Example 4 with BroadcastingDispatcher

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

the class PublishSubscribeChannelParserTests method ignoreFailures.

@Test
public void ignoreFailures() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithIgnoreFailures");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    assertTrue((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("ignoreFailures"));
    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 5 with BroadcastingDispatcher

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

the class PublishSubscribeChannelParserTests method ignoreFailuresWithTaskExecutor.

@Test
public void ignoreFailuresWithTaskExecutor() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithIgnoreFailuresAndTaskExecutor");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
    assertTrue((Boolean) dispatcherAccessor.getPropertyValue("ignoreFailures"));
    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)

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