GH-1240 Additional fixes related to 5a9c6a6162

This commit is contained in:
Oleg Zhurakousky
2019-02-04 10:44:23 +01:00
parent f01cb29b44
commit 5b39e57ac9

View File

@@ -581,10 +581,8 @@ public abstract class AbstractMessageChannelBinder<C extends ConsumerProperties,
SubscribableChannel errorChannel;
if (getApplicationContext().containsBean(errorChannelName)) {
Object errorChannelObject = getApplicationContext().getBean(errorChannelName);
if (!(errorChannelObject instanceof SubscribableChannel)) {
throw new IllegalStateException(
"Error channel '" + errorChannelName + "' must be a SubscribableChannel");
}
Assert.isInstanceOf(SubscribableChannel.class, errorChannelObject,
"Error channel '" + errorChannelName + "' must be a SubscribableChannel");
errorChannel = (SubscribableChannel) errorChannelObject;
}
else {
@@ -677,9 +675,7 @@ public abstract class AbstractMessageChannelBinder<C extends ConsumerProperties,
private void destroyErrorInfrastructure(ConsumerDestination destination, String group, C properties) {
try {
String recoverer = getErrorRecovererName(destination, group, properties);
if (getApplicationContext().containsBean(recoverer)) {
((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory()).destroySingleton(recoverer);
}
destroyBean(recoverer);
String errorChannelName = errorsBaseName(destination, group, properties);
String errorMessageHandlerName = getErrorMessageHandlerName(destination, group, properties);
String errorBridgeHandlerName = getErrorBridgeName(destination, group, properties);
@@ -695,16 +691,13 @@ public abstract class AbstractMessageChannelBinder<C extends ConsumerProperties,
SubscribableChannel channel = getApplicationContext().getBean(errorChannelName, SubscribableChannel.class);
if (bridgeHandler != null) {
channel.unsubscribe(bridgeHandler);
((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
.destroySingleton(errorBridgeHandlerName);
destroyBean(errorBridgeHandlerName);
}
if (handler != null) {
channel.unsubscribe(handler);
((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
.destroySingleton(errorMessageHandlerName);
destroyBean(errorMessageHandlerName);
}
((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory())
.destroySingleton(errorChannelName);
destroyBean(errorChannelName);
}
}
catch (IllegalStateException e) {
@@ -712,6 +705,13 @@ public abstract class AbstractMessageChannelBinder<C extends ConsumerProperties,
}
}
private void destroyBean(String beanName) {
if (getApplicationContext().containsBean(beanName)) {
((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory()).destroySingleton(beanName);
((GenericApplicationContext)getApplicationContext()).removeBeanDefinition(beanName);
}
}
/**
* Binders can return a message handler to be subscribed to the error channel.
* Examples might be if the user wishes to (re)publish messages to a DLQ.