From c92bb1f0aad297ceb9253bd0dce88df9b5c2235f Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 31 Aug 2022 13:33:37 +0200 Subject: [PATCH] GH-2501 Maje StreamBridge 'safer' if created outside of Spring Resolves #2501 --- .../cloud/stream/function/StreamBridge.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/function/StreamBridge.java b/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/function/StreamBridge.java index 09f0b4992..8d7e89c17 100644 --- a/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/function/StreamBridge.java +++ b/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/function/StreamBridge.java @@ -52,6 +52,7 @@ import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.GenericMessage; +import org.springframework.util.Assert; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; import org.springframework.util.StringUtils; @@ -107,6 +108,9 @@ public final class StreamBridge implements SmartInitializingSingleton { @SuppressWarnings("serial") StreamBridge(FunctionCatalog functionCatalog, BindingServiceProperties bindingServiceProperties, ConfigurableApplicationContext applicationContext, @Nullable NewDestinationBindingCallback destinationBindingCallback) { + Assert.notNull(functionCatalog, "'functionCatalog' must not be null"); + Assert.notNull(applicationContext, "'applicationContext' must not be null"); + Assert.notNull(bindingServiceProperties, "'bindingServiceProperties' must not be null"); this.bindingService = applicationContext.getBean(BindingService.class); this.functionCatalog = functionCatalog; this.applicationContext = applicationContext; @@ -208,7 +212,9 @@ public final class StreamBridge implements SmartInitializingSingleton { */ @SuppressWarnings({ "unchecked"}) public boolean send(String bindingName, @Nullable String binderName, Object data, MimeType outputContentType) { - + if (!this.initialized) { + this.afterSingletonsInstantiated(); + } ProducerProperties producerProperties = this.bindingServiceProperties.getProducerProperties(bindingName); MessageChannel messageChannel = this.resolveDestination(bindingName, producerProperties, binderName);