|
53 | 53 | import org.springframework.cloud.stream.config.BindingProperties; |
54 | 54 | import org.springframework.cloud.stream.config.BindingServiceProperties; |
55 | 55 | import org.springframework.cloud.stream.messaging.DirectWithAttributesChannel; |
| 56 | +import org.springframework.context.ApplicationEvent; |
| 57 | +import org.springframework.context.ApplicationListener; |
56 | 58 | import org.springframework.context.ConfigurableApplicationContext; |
57 | 59 | import org.springframework.core.ResolvableType; |
58 | 60 | import org.springframework.integration.channel.AbstractMessageChannel; |
|
95 | 97 | * |
96 | 98 | */ |
97 | 99 | @SuppressWarnings("rawtypes") |
98 | | -public final class StreamBridge implements StreamOperations, SmartInitializingSingleton, DisposableBean { |
| 100 | +public final class StreamBridge implements StreamOperations, SmartInitializingSingleton, DisposableBean, ApplicationListener<ApplicationEvent> { |
99 | 101 |
|
100 | 102 | private static final String STREAM_BRIDGE_FUNC_NAME = "streamBridge"; |
101 | 103 |
|
@@ -135,6 +137,7 @@ public final class StreamBridge implements StreamOperations, SmartInitializingSi |
135 | 137 | * @param bindingServiceProperties instance of {@link BindingServiceProperties} |
136 | 138 | * @param applicationContext instance of {@link ConfigurableApplicationContext} |
137 | 139 | */ |
| 140 | + @SuppressWarnings("serial") |
138 | 141 | StreamBridge(FunctionCatalog functionCatalog, BindingServiceProperties bindingServiceProperties, |
139 | 142 | ConfigurableApplicationContext applicationContext, @Nullable NewDestinationBindingCallback destinationBindingCallback, ObjectProvider<ObservationRegistry> observationRegistries) { |
140 | 143 | this.executorService = Executors.newCachedThreadPool(); |
@@ -292,12 +295,9 @@ MessageChannel resolveDestination(String destinationName, ProducerProperties pro |
292 | 295 | messageChannel = this.isAsync() ? new ExecutorChannel(this.executorService) : new DirectWithAttributesChannel(); |
293 | 296 | ((AbstractSubscribableChannel) messageChannel).setApplicationContext(applicationContext); |
294 | 297 | ((AbstractSubscribableChannel) messageChannel).setComponentName(destinationName); |
295 | | -//<<<<<<< HEAD |
296 | 298 |
|
297 | 299 | BinderWrapper binderWrapper = bindingService.createBinderWrapper(binderName, destinationName, messageChannel.getClass()); |
298 | | -//======= |
299 | 300 | ((AbstractSubscribableChannel) messageChannel).registerObservationRegistry(observationRegistry); |
300 | | -//>>>>>>> a1418283c (GH-3033: Register ObservationRegistry for Dynamic MessageChannels) |
301 | 301 | if (this.destinationBindingCallback != null) { |
302 | 302 | Object extendedProducerProperties = this.bindingService |
303 | 303 | .getExtendedProducerProperties(binderWrapper.binder(), destinationName); |
@@ -369,6 +369,15 @@ public void setAsync(boolean async) { |
369 | 369 | this.async = async; |
370 | 370 | } |
371 | 371 |
|
| 372 | + // see https://github.com/spring-cloud/spring-cloud-stream/issues/3054 |
| 373 | + @Override |
| 374 | + public void onApplicationEvent(ApplicationEvent event) { |
| 375 | + // we need to do it by String to avoid cloud-bus and context dependencies |
| 376 | + if (event.getClass().getName().equals("org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent")) { |
| 377 | + this.channelCache.clear(); |
| 378 | + } |
| 379 | + } |
| 380 | + |
372 | 381 | private static final class ContextPropagationHelper { |
373 | 382 | static ExecutorService wrap(ExecutorService executorService) { |
374 | 383 | return ContextExecutorService.wrap(executorService, () -> ContextSnapshotFactory.builder().build().captureAll()); |
|
0 commit comments