Class StreamBridge

java.lang.Object
org.springframework.cloud.stream.function.StreamBridge
All Implemented Interfaces:
org.springframework.beans.factory.SmartInitializingSingleton

public final class StreamBridge extends Object implements org.springframework.beans.factory.SmartInitializingSingleton
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 of 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.
Since:
3.0.3
Author:
Oleg Zhurakousky, Soby Chacko
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    boolean
    send(String bindingName, Object data)
    Sends 'data' to an output binding specified by 'bindingName' argument while using default content type to deal with output type conversion (if necessary).
    boolean
    send(String bindingName, 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).
    boolean
    send(String bindingName, String binderName, Object data)
    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).
    boolean
    send(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).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • send

      public boolean send(String bindingName, Object data)
      Sends '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 see send(String, String, Object) and send(String, String, Object, MimeType) methods.
      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 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)
      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). 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 see send(String, String, Object) and send(String, String, Object, MimeType) methods.
      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 send
      outputContentType - 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

      public boolean send(String bindingName, @Nullable String binderName, Object data)
      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). 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.
      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)
      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). 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.
      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
      outputContentType - 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:
      afterSingletonsInstantiated in interface org.springframework.beans.factory.SmartInitializingSingleton