This section describes the programming model for spring Cloud stream. Spring Cloud Stream provides a number of predefined annotations that declare the input and output channels of the binding, and how to listen to the channel.
declaring and binding channelsTriggering bindings
@EnableBinding
You can convert a spring application into a spring Cloud stream application and @EnableBinding apply annotations to one of the application's configuration classes. the @EnableBinding comment itself uses @Configuration meta-annotations and triggers the configuration of the spring Cloud stream infrastructure:
... @Import (...) @Configuration @enableintegrationpublic @interface enablebinding { ... Class<?>[] Value () default {};}
@EnableBindingNote You can use one or more interface classes as parameters that contain methods that represent bindable components, which are typically message channels.
| Attention |
in Spring Cloud Stream 1.0, the only supported bindable component is spring message delivery MessageChannel with its extension SubscribableChannel and PollableChannel . Future versions should use the same mechanism to extend this support to other types of components. In this document, we will continue to refer to the channel. |
@Input and
@Output the
The Spring Cloud Stream application can define any number of input and output channels as the and methods in the interface @Input @Output :
Public interface Barista { @Input subscribablechannel orders (); @Output Messagechannel hotdrinks (); @Output Messagechannel colddrinks ();}
Use this interface as a parameter to @EnableBinding trigger a three-bound channel name orders , respectively, hotDrinks and coldDrinks .
@EnableBinding (barista.class) public class Cafeconfiguration { ...}
Custom channel name
Using @Input and @Output commenting, you can specify a custom channel name for the channel, as shown in the following example:
Public interface Barista { ... @Input ("Inboundorders") Subscribablechannel orders ();}
In this example, the binding channel created will be named inboundOrders .
Source ,
Sink and
Processor
To facilitate addressing the most common use cases, involving input channels, output channels, or both, Spring Cloud Stream provides three predefined interfaces out-of-the-box.
SourceAvailable for applications with a single outbound channel.
Public interface Source { String output = "Output"; @Output (source.output) Messagechannel Output ();}
SinkAvailable for applications with a single inbound channel.
Public interface Sink { String input = "INPUT"; @Input (sink.input) Subscribablechannel Input ();}
ProcessorAvailable for applications with inbound and outbound channels.
Public interface Processor extends Source, Sink {}
Spring Cloud Stream does not provide special handling for any of these interfaces; They're just out of the box. SOURCE Source
Spring Cloud Stream Tutorial (v) programming model