Annotation Type StreamListener
@Target({METHOD,ANNOTATION_TYPE})
@Retention(RUNTIME)
@MessageMapping
@Documented
@Deprecated
public @interface StreamListener
Deprecated.
as of 3.1 in favor of functional programming model
NOTE: It is no longer recommended to use StreamListener in favor of functional programming model.
It will be deprecated and subsequently removed in the future
Annotation that marks a method to be a listener to inputs declared via
Annotation that marks a method to be a listener to inputs declared via
EnableBinding (e.g. channels).
Annotated methods are allowed to have flexible signatures, which determine how the
method is invoked and how their return results are processed. This annotation can be
applied for two separate classes of methods.
Declarative mode
A method is considered declarative if all its method parameter types and return type (if not void) are binding targets or conversion targets from binding targets via a registeredStreamListenerParameterAdapter.
Only declarative methods can have binding targets or conversion targets as arguments
and return type.
Declarative methods must specify what inputs and outputs correspond to their arguments
and return type, and can do this in one of the following ways.
- By using either the
InputorOutputannotation for each of the parameters and theOutputannotation on the method for the return type (if applicable). The use of annotations in this case is mandatory. In this case theStreamListenerannotation must not specify a value. - By setting an
Inputbound target as the annotation value ofStreamListenerand usingSendToon the method for the return type (if applicable). In this case the method must have exactly one parameter, corresponding to an input.
@StreamListener
public @Output("joined") Flux<String> join(
@Input("input1") Flux<String> input1,
@Input("input2") Flux<String> input2) {
// ... join the two input streams via functional operators
}
An example of declarative method signature using the latter idiom is as follows:
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public Flux<String> convert(Flux<String> input) {
return input.map(String::toUppercase);
}
Declarative methods are invoked only once, when the context is refreshed.
Individual message handler mode
Non declarative methods are treated as message handler based, and are invoked for each incoming message received from that target. In this case, the method can have a flexible signature, as described byMessageMapping.
If the method returns a Message, the result will
be automatically sent to a binding target, as follows:
- A result of the type
Messagewill be sent as-is - All other results will become the payload of a
Message
- The
MessageHeadersof the resulting message. - The value set on the
SendToannotation, if present
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public String convert(String input) {
return input.toUppercase();
}
- Author:
- Marius Bogoevici, Ilayaperumal Gopinathan, Gary Russell
- See Also:
-
MessageMappingEnableBindingSendTo
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionDeprecated.A condition that must be met by all items that are dispatched to this method.Deprecated.When "true" (default), and a@SendToannotation is present, copy the inbound headers to the outbound message (if the header is absent on the outbound message).Deprecated.The name of the binding target (e.g.Deprecated.The name of the binding target (e.g.
-
Element Details
-
value
Deprecated.The name of the binding target (e.g. channel) that the method subscribes to.- Returns:
- the name of the binding target.
- Default:
- ""
-
target
Deprecated.The name of the binding target (e.g. channel) that the method subscribes to.- Returns:
- the name of the binding target.
- Default:
- ""
-
condition
String conditionDeprecated.A condition that must be met by all items that are dispatched to this method.- Returns:
- a SpEL expression that must evaluate to a
booleanvalue.
- Default:
- ""
-
copyHeaders
String copyHeadersDeprecated.When "true" (default), and a@SendToannotation is present, copy the inbound headers to the outbound message (if the header is absent on the outbound message). Can be an expression (#{...}) or property placeholder. Must resolve to a boolean or a string that is parsed byBoolean.parseBoolean(). An expression that resolves tonullis interpreted to meanfalse. The expression is evaluated during application initialization, and not for each individual message. Prior to version 1.3.0, the default value used to be "false" and headers were not propagated by default. Starting with version 1.3.0, the default value is "true".- Returns:
Booleanin a String format- Since:
- 1.2.3
- Default:
- "true"
-