Class StreamBridge
java.lang.Object
org.springframework.cloud.stream.function.StreamBridge
- All Implemented Interfaces:
EventListener, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.SmartInitializingSingleton, StreamOperations, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
public final class StreamBridge
extends Object
implements StreamOperations, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
A class which allows user to send data to an output binding.
While in a common scenario of a typical spring-cloud-stream application user rarely
has to manually send data, there are times when the sources of data are outside
spring-cloud-stream context, and therefore we need to bridge such foreign sources
with spring-cloud-stream.
This utility class allows user to do just that - bridge non-spring-cloud-stream applications with spring-cloud-stream by providing a mechanism (bridge) to send data to an output binding while maintaining the same invocation contract (i.e., type conversion, partitioning etc.) as if it was done through a declared function.
This utility class allows user to do just that - bridge non-spring-cloud-stream applications with spring-cloud-stream by providing a mechanism (bridge) to send data to an output binding while maintaining the same invocation contract (i.e., type conversion, partitioning etc.) as if it was done through a declared function.
- Since:
- 3.0.3
- Author:
- Oleg Zhurakousky, Soby Chacko, Byungjun You, MichaĆ Rowicki, Omer Celik
-
Method Summary
Modifier and TypeMethodDescriptionvoidvoiddestroy()booleanisAsync()voidonApplicationEvent(org.springframework.context.ApplicationEvent event) booleanSends 'data' to an output binding specified by 'bindingName' argument while using default content type to deal with output type conversion (if necessary).booleanSends 'data' to an output binding specified by 'bindingName' argument while using the content type specified by the 'outputContentType' argument to deal with output type conversion (if necessary).booleanSends 'data' to an output binding specified by 'bindingName' argument while using the content type specified by the 'outputContentType' argument to deal with output type conversion (if necessary).booleansend(String bindingName, String binderName, Object data, org.springframework.util.MimeType outputContentType) Sends 'data' to an output binding specified by 'bindingName' argument while using the content type specified by the 'outputContentType' argument to deal with output type conversion (if necessary).voidsetAsync(boolean async) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Method Details
-
send
Description copied from interface:StreamOperationsSends 'data' to an output binding specified by 'bindingName' argument while using default content type to deal with output type conversion (if necessary). For typical cases `bindingName` is configured using 'spring.cloud.stream.source' property. However, this operation also supports sending to truly dynamic destinations. This means if the name provided via 'bindingName' does not have a corresponding binding such name will be treated as dynamic destination.
Will use default binder. For specific binder type seeStreamOperations.send(String, String, Object)andStreamOperations.send(String, String, Object, MimeType)methods.- Specified by:
sendin interfaceStreamOperations- Parameters:
bindingName- the name of the output binding. That said it requires a bit of clarification. When using send("foo"...), the 'foo' typically represents the binding name. However, if such binding does not exist, the new binding will be created to support dynamic destinations.data- the data to send- Returns:
- true if data was sent successfully, otherwise false or throws an exception.
-
send
public boolean send(String bindingName, Object data, org.springframework.util.MimeType outputContentType) Description copied from interface:StreamOperationsSends 'data' to an output binding specified by 'bindingName' argument while using the content type specified by the 'outputContentType' argument to deal with output type conversion (if necessary). For typical cases `bindingName` is configured using 'spring.cloud.stream.source' property. However, this operation also supports sending to truly dynamic destinations. This means if the name provided via 'bindingName' does not have a corresponding binding such name will be treated as dynamic destination.
Will use default binder. For specific binder type seeStreamOperations.send(String, String, Object)andStreamOperations.send(String, String, Object, MimeType)methods.- Specified by:
sendin interfaceStreamOperations- Parameters:
bindingName- the name of the output binding. That said it requires a bit of clarification. When using bridge.send("foo"...), the 'foo' typically represents the binding name. However, if such binding does not exist, the new binding will be created to support dynamic destinations.data- the data to sendoutputContentType- content type to be used to deal with output type conversion- Returns:
- true if data was sent successfully, otherwise false or throws an exception.
-
send
Description copied from interface:StreamOperationsSends 'data' to an output binding specified by 'bindingName' argument while using the content type specified by the 'outputContentType' argument to deal with output type conversion (if necessary). For typical cases `bindingName` is configured using 'spring.cloud.stream.source' property. However, this operation also supports sending to truly dynamic destinations. This means if the name provided via 'bindingName' does not have a corresponding binding such name will be treated as dynamic destination.- Specified by:
sendin interfaceStreamOperations- Parameters:
bindingName- the name of the output binding. That said it requires a bit of clarification. When using bridge.send("foo"...), the 'foo' typically represents the binding name. However, if such binding does not exist, the new binding will be created to support dynamic destinations.binderName- the name of the binder to use (e.g., 'kafka', 'rabbit') for cases where multiple binders are used. Can be null.data- the data to send- Returns:
- true if data was sent successfully, otherwise false or throws an exception.
-
send
public boolean send(String bindingName, @Nullable String binderName, Object data, org.springframework.util.MimeType outputContentType) Description copied from interface:StreamOperationsSends 'data' to an output binding specified by 'bindingName' argument while using the content type specified by the 'outputContentType' argument to deal with output type conversion (if necessary). For typical cases `bindingName` is configured using 'spring.cloud.stream.source' property. However, this operation also supports sending to truly dynamic destinations. This means if the name provided via 'bindingName' does not have a corresponding binding such name will be treated as dynamic destination.- Specified by:
sendin interfaceStreamOperations- Parameters:
bindingName- the name of the output binding. That said it requires a bit of clarification. When using bridge.send("foo"...), the 'foo' typically represents the binding name. However, if such binding does not exist, the new binding will be created to support dynamic destinations.binderName- the name of the binder to use (e.g., 'kafka', 'rabbit') for cases where multiple binders are used. Can be null.data- the data to sendoutputContentType- content type to be used to deal with output type conversion- Returns:
- true if data was sent successfully, otherwise false or throws an exception.
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiatedin interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
destroy
-
isAsync
public boolean isAsync() -
setAsync
public void setAsync(boolean async) -
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent event) - Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
-