Spring Cloud Stream Tutorial (v) programming model

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.