Example usage for org.springframework.messaging SubscribableChannel unsubscribe

List of usage examples for org.springframework.messaging SubscribableChannel unsubscribe

Introduction

In this page you can find the example usage for org.springframework.messaging SubscribableChannel unsubscribe.

Prototype

boolean unsubscribe(MessageHandler handler);

Source Link

Document

Un-register a message handler.

Usage

From source file:org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.java

private void destroyErrorInfrastructure(ProducerDestination destination) {
    String errorChannelName = errorsBaseName(destination);
    String errorBridgeHandlerName = getErrorBridgeName(destination);
    MessageHandler bridgeHandler = null;
    if (getApplicationContext().containsBean(errorBridgeHandlerName)) {
        bridgeHandler = getApplicationContext().getBean(errorBridgeHandlerName, MessageHandler.class);
    }/*from w ww .  ja  v a2 s.c om*/
    if (getApplicationContext().containsBean(errorChannelName)) {
        SubscribableChannel channel = getApplicationContext().getBean(errorChannelName,
                SubscribableChannel.class);
        if (bridgeHandler != null) {
            channel.unsubscribe(bridgeHandler);
            ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
                    .destroySingleton(errorBridgeHandlerName);
        }
        ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
                .destroySingleton(errorChannelName);
    }
}

From source file:org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.java

private void destroyErrorInfrastructure(ConsumerDestination destination, String group, C properties) {
    try {//from  w ww .  ja  va2  s  .c  o  m
        String recoverer = getErrorRecovererName(destination, group, properties);
        if (getApplicationContext().containsBean(recoverer)) {
            ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
                    .destroySingleton(recoverer);
        }
        String errorChannelName = errorsBaseName(destination, group, properties);
        String errorMessageHandlerName = getErrorMessageHandlerName(destination, group, properties);
        String errorBridgeHandlerName = getErrorBridgeName(destination, group, properties);
        MessageHandler bridgeHandler = null;
        if (getApplicationContext().containsBean(errorBridgeHandlerName)) {
            bridgeHandler = getApplicationContext().getBean(errorBridgeHandlerName, MessageHandler.class);
        }
        MessageHandler handler = null;
        if (getApplicationContext().containsBean(errorMessageHandlerName)) {
            handler = getApplicationContext().getBean(errorMessageHandlerName, MessageHandler.class);
        }
        if (getApplicationContext().containsBean(errorChannelName)) {
            SubscribableChannel channel = getApplicationContext().getBean(errorChannelName,
                    SubscribableChannel.class);
            if (bridgeHandler != null) {
                channel.unsubscribe(bridgeHandler);
                ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
                        .destroySingleton(errorBridgeHandlerName);
            }
            if (handler != null) {
                channel.unsubscribe(handler);
                ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
                        .destroySingleton(errorMessageHandlerName);
            }
            ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
                    .destroySingleton(errorChannelName);
        }
    } catch (IllegalStateException e) {
        // context is shutting down.
    }
}