@Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @MessageMapping @Documented public @interface StreamListener
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.
StreamListenerParameterAdapter
.
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.
Input
or Output
annotation for each of the
parameters and the Output
annotation on the method for the return type (if
applicable). The use of annotations in this case is mandatory. In this case the
StreamListener
annotation must not specify a value.Input
bound target as the annotation value of
StreamListener
and using
SendTo
on 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.
MessageMapping
.
If the method returns a Message
, the result will
be automatically sent to a binding target, as follows:
Message
will be sent
as-isMessage
MessageHeaders
of the resulting
message.SendTo
annotation, if
present@StreamListener(Processor.INPUT) @SendTo(Processor.OUTPUT) public String convert(String input) { return input.toUppercase(); }
MessageMapping
,
EnableBinding
,
SendTo
Modifier and Type | Optional Element and Description |
---|---|
String |
condition
A condition that must be met by all items that are dispatched to this method.
|
String |
copyHeaders
When "true" (default), and a
@SendTo annotation is present, copy the
inbound headers to the outbound message (if the header is absent on the outbound
message). |
String |
target
The name of the binding target (e.g.
|
String |
value
The name of the binding target (e.g.
|
@AliasFor(value="target") public abstract String value
@AliasFor(value="value") public abstract String target
public abstract String condition
boolean
value.public abstract String copyHeaders
@SendTo
annotation 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 by Boolean.parseBoolean()
.
An expression that resolves to null
is interpreted to mean false
.
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".Boolean
in a String formatCopyright © 2020 Pivotal Software, Inc.. All rights reserved.