Search in sources :

Example 1 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-cloud-stream by spring-cloud.

the class TestChannelBinder method createProducerMessageHandler.

@Override
protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ProducerProperties producerProperties, MessageChannel errorChannel) throws Exception {
    BridgeHandler handler = new BridgeHandler();
    handler.setBeanFactory(this.beanFactory);
    handler.setOutputChannel(((SpringIntegrationProducerDestination) destination).getChannel());
    return handler;
}
Also used : BridgeHandler(org.springframework.integration.handler.BridgeHandler)

Example 2 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-cloud-stream by spring-cloud.

the class BindingServiceConfiguration method errorBridgeChannel.

@Bean
@ConditionalOnProperty("spring.cloud.stream.bindings." + ERROR_KEY_NAME + ".destination")
public MessageChannel errorBridgeChannel(@Qualifier(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME) PublishSubscribeChannel errorChannel) {
    SubscribableChannel errorBridgeChannel = new DirectChannel();
    BridgeHandler handler = new BridgeHandler();
    handler.setOutputChannel(errorBridgeChannel);
    errorChannel.subscribe(handler);
    return errorBridgeChannel;
}
Also used : DirectChannel(org.springframework.integration.channel.DirectChannel) BridgeHandler(org.springframework.integration.handler.BridgeHandler) SubscribableChannel(org.springframework.messaging.SubscribableChannel) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 3 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-cloud-stream by spring-cloud.

the class MessageChannelStreamListenerResultAdapter method adapt.

@Override
public Closeable adapt(MessageChannel streamListenerResult, MessageChannel bindingTarget) {
    BridgeHandler handler = new BridgeHandler();
    handler.setOutputChannel(bindingTarget);
    handler.afterPropertiesSet();
    ((SubscribableChannel) streamListenerResult).subscribe(handler);
    return new NoOpCloseeable();
}
Also used : BridgeHandler(org.springframework.integration.handler.BridgeHandler) SubscribableChannel(org.springframework.messaging.SubscribableChannel)

Example 4 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-cloud-stream by spring-cloud.

the class AbstractMessageChannelBinder method registerErrorInfrastructure.

/**
 * Register an error channel for the destination when an async send error is received.
 * Bridge the channel to the global error channel (if present).
 * @param destination the destination.
 * @return the channel.
 */
private SubscribableChannel registerErrorInfrastructure(ProducerDestination destination) {
    ConfigurableListableBeanFactory beanFactory = getApplicationContext().getBeanFactory();
    String errorChannelName = errorsBaseName(destination);
    SubscribableChannel errorChannel = null;
    if (getApplicationContext().containsBean(errorChannelName)) {
        Object errorChannelObject = getApplicationContext().getBean(errorChannelName);
        if (!(errorChannelObject instanceof SubscribableChannel)) {
            throw new IllegalStateException("Error channel '" + errorChannelName + "' must be a SubscribableChannel");
        }
        errorChannel = (SubscribableChannel) errorChannelObject;
    } else {
        errorChannel = new PublishSubscribeChannel();
        beanFactory.registerSingleton(errorChannelName, errorChannel);
        errorChannel = (PublishSubscribeChannel) beanFactory.initializeBean(errorChannel, errorChannelName);
    }
    MessageChannel defaultErrorChannel = null;
    if (getApplicationContext().containsBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)) {
        defaultErrorChannel = getApplicationContext().getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, MessageChannel.class);
    }
    if (defaultErrorChannel != null) {
        BridgeHandler errorBridge = new BridgeHandler();
        errorBridge.setOutputChannel(defaultErrorChannel);
        errorChannel.subscribe(errorBridge);
        String errorBridgeHandlerName = getErrorBridgeName(destination);
        beanFactory.registerSingleton(errorBridgeHandlerName, errorBridge);
        beanFactory.initializeBean(errorBridge, errorBridgeHandlerName);
    }
    return errorChannel;
}
Also used : PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) MessageChannel(org.springframework.messaging.MessageChannel) BridgeHandler(org.springframework.integration.handler.BridgeHandler) SubscribableChannel(org.springframework.messaging.SubscribableChannel) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 5 with BridgeHandler

use of org.springframework.integration.handler.BridgeHandler in project spring-cloud-stream by spring-cloud.

the class AbstractMessageChannelBinder method registerErrorInfrastructure.

/**
 * Build an errorChannelRecoverer that writes to a pub/sub channel for the destination
 * when an exception is thrown to a consumer.
 * @param destination the destination.
 * @param group the group.
 * @param consumerProperties the properties.
 * @param polled true if this is for a polled consumer.
 * @return the ErrorInfrastructure which is a holder for the error channel, the recoverer and the
 * message handler that is subscribed to the channel.
 */
protected final ErrorInfrastructure registerErrorInfrastructure(ConsumerDestination destination, String group, C consumerProperties, boolean polled) {
    ErrorMessageStrategy errorMessageStrategy = getErrorMessageStrategy();
    ConfigurableListableBeanFactory beanFactory = getApplicationContext().getBeanFactory();
    String errorChannelName = errorsBaseName(destination, group, consumerProperties);
    SubscribableChannel errorChannel = null;
    if (getApplicationContext().containsBean(errorChannelName)) {
        Object errorChannelObject = getApplicationContext().getBean(errorChannelName);
        if (!(errorChannelObject instanceof SubscribableChannel)) {
            throw new IllegalStateException("Error channel '" + errorChannelName + "' must be a SubscribableChannel");
        }
        errorChannel = (SubscribableChannel) errorChannelObject;
    } else {
        errorChannel = new BinderErrorChannel();
        beanFactory.registerSingleton(errorChannelName, errorChannel);
        errorChannel = (LastSubscriberAwareChannel) beanFactory.initializeBean(errorChannel, errorChannelName);
    }
    ErrorMessageSendingRecoverer recoverer;
    if (errorMessageStrategy == null) {
        recoverer = new ErrorMessageSendingRecoverer(errorChannel);
    } else {
        recoverer = new ErrorMessageSendingRecoverer(errorChannel, errorMessageStrategy);
    }
    String recovererBeanName = getErrorRecovererName(destination, group, consumerProperties);
    beanFactory.registerSingleton(recovererBeanName, recoverer);
    beanFactory.initializeBean(recoverer, recovererBeanName);
    MessageHandler handler;
    if (polled) {
        handler = getPolledConsumerErrorMessageHandler(destination, group, consumerProperties);
    } else {
        handler = getErrorMessageHandler(destination, group, consumerProperties);
    }
    MessageChannel defaultErrorChannel = null;
    if (getApplicationContext().containsBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)) {
        defaultErrorChannel = getApplicationContext().getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, MessageChannel.class);
    }
    if (handler == null && errorChannel instanceof LastSubscriberAwareChannel) {
        handler = getDefaultErrorMessageHandler((LastSubscriberAwareChannel) errorChannel, defaultErrorChannel != null);
    }
    String errorMessageHandlerName = getErrorMessageHandlerName(destination, group, consumerProperties);
    if (handler != null) {
        beanFactory.registerSingleton(errorMessageHandlerName, handler);
        beanFactory.initializeBean(handler, errorMessageHandlerName);
        errorChannel.subscribe(handler);
    }
    if (defaultErrorChannel != null) {
        BridgeHandler errorBridge = new BridgeHandler();
        errorBridge.setOutputChannel(defaultErrorChannel);
        errorChannel.subscribe(errorBridge);
        String errorBridgeHandlerName = getErrorBridgeName(destination, group, consumerProperties);
        beanFactory.registerSingleton(errorBridgeHandlerName, errorBridge);
        beanFactory.initializeBean(errorBridge, errorBridgeHandlerName);
    }
    return new ErrorInfrastructure(errorChannel, recoverer, handler);
}
Also used : AbstractMessageHandler(org.springframework.integration.handler.AbstractMessageHandler) MessageHandler(org.springframework.messaging.MessageHandler) ErrorMessageStrategy(org.springframework.integration.support.ErrorMessageStrategy) BridgeHandler(org.springframework.integration.handler.BridgeHandler) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) MessageChannel(org.springframework.messaging.MessageChannel) ErrorMessageSendingRecoverer(org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer) SubscribableChannel(org.springframework.messaging.SubscribableChannel) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Aggregations

BridgeHandler (org.springframework.integration.handler.BridgeHandler)11 SubscribableChannel (org.springframework.messaging.SubscribableChannel)5 MessageChannel (org.springframework.messaging.MessageChannel)3 Test (org.junit.Test)2 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)2 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 Message (org.springframework.messaging.Message)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1 Bean (org.springframework.context.annotation.Bean)1 FixedSubscriberChannel (org.springframework.integration.channel.FixedSubscriberChannel)1 PublishSubscribeChannel (org.springframework.integration.channel.PublishSubscribeChannel)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 ReactiveStreamsSubscribableChannel (org.springframework.integration.channel.ReactiveStreamsSubscribableChannel)1