Spring Cloud Stream: Difference between revisions
Line 27: | Line 27: | ||
==Channel Factory Interfaces== | ==Channel Factory Interfaces== | ||
<span id='Sink'></span><tt>Sink</tt> is an [[#Input_Channel|input channel]] factory: | <span id='Sink'></span><tt>Sink</tt> is an [[#Input_Channel|input channel]] factory. It uses the [[@Input]] annotation to indicate that an input binding target will be created by the framework: | ||
<syntaxhighlight lang='java'> | <syntaxhighlight lang='java'> | ||
Line 38: | Line 38: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<span id='Source'></span><tt>Source</tt> is an [[#Output_Channel|output channel]] factory: | <span id='Source'></span><tt>Source</tt> is an [[#Output_Channel|output channel]] factory. It uses the [[@Output]] annotation to indicate that an output binding target will be created by the framework: | ||
<syntaxhighlight lang='java'> | <syntaxhighlight lang='java'> | ||
Line 56: | Line 56: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The [[@Input]] and [[@Output]] annotations can be used directly to mark input and output channel factory methods on a custom interface: | |||
<syntaxhighlight lang='java'> | |||
public interface MyCustomBidirectionalOutfit { | |||
String INPUT_CHANNEL_BEAN_NAME = "input-channel"; | |||
String OUTPUT_CHANNEL_BEAN_NAME = "output-channel"; | |||
@Input(INPUT_CHANNEL_BEAN_NAME) | |||
SubscribableChannel inputChannel(); | |||
@Output(OUTPUT_CHANNEL_BEAN_NAME) | |||
MessageChannel outputChannel(); | |||
} | |||
</syntaxhighlight> | |||
<tt>[[#Sink|Sink]]</tt>, <tt>[[#Source|Source]]</tt>, <tt>[[#Processor|Processor]]</tt> and custom interfaces annotated with [[@Input]] and [[@Output]] can be used to configure the [[@EnableBinding]] annotation. | |||
==Testing== | ==Testing== | ||
=Configuration= | =Configuration= |
Revision as of 03:40, 24 October 2018
External
- https://cloud.spring.io/spring-cloud-stream/
- https://cloud.spring.io/spring-cloud-stream-app-starters/
- Reference Spring Cloud Stream Core https://docs.spring.io/spring-cloud-stream/docs/Elmhurst.RELEASE/reference/htmlsingle/#_spring_cloud_stream_core
Internal
Overview
Spring Cloud Stream is a framework for building highly scalable event-driven microservices connected with shared messaging systems. Spring applications use Spring Cloud Stream libraries to bind to messaging middleware, using a middleware-specific-neutral API. The application uses input and output channel channel abstractions injected into it by Spring Cloud Stream runtime. Channels are connected to brokers through middleware-specific binder implementations.
Spring Cloud Stream builds upon Spring Boot to create standalone production-grade applications. Spring Initializr lists Spring Cloud Stream under "Cloud Messaging"
Concepts
Binder
Channel
An input channel is an object present in the memory of a Spring application whose implementation is transparently created by Spring Cloud Stream and injected int the application. The application uses input channel to receive messages. Similarly, an output channel is also an object created and injected by Spring Cloud Stream into the application. Application sends messages via output channels. The Spring Cloud Stream API conveniently provides factory interfaces for producing input channels (Sink), output channels (Source) and both input and output channels (Processor).
Programming Model
Channel Factory Interfaces
Sink is an input channel factory. It uses the @Input annotation to indicate that an input binding target will be created by the framework:
public interface Sink {
String INPUT = "input";
@Input(Sink.INPUT)
SubscribableChannel input();
}
Source is an output channel factory. It uses the @Output annotation to indicate that an output binding target will be created by the framework:
public interface Source {
String OUTPUT = "output";
@Output(Source.OUTPUT)
MessageChannel output();
}
Processor is an factory for both input and output channels:
public interface Processor extends Source, Sink {
}
The @Input and @Output annotations can be used directly to mark input and output channel factory methods on a custom interface:
public interface MyCustomBidirectionalOutfit {
String INPUT_CHANNEL_BEAN_NAME = "input-channel";
String OUTPUT_CHANNEL_BEAN_NAME = "output-channel";
@Input(INPUT_CHANNEL_BEAN_NAME)
SubscribableChannel inputChannel();
@Output(OUTPUT_CHANNEL_BEAN_NAME)
MessageChannel outputChannel();
}
Sink, Source, Processor and custom interfaces annotated with @Input and @Output can be used to configure the @EnableBinding annotation.