Broadcast
Experimental
|
By default, messages transiting in a channel are only dispatched to a single consumer. Having multiple consumers is considered as an error, and is reported at deployment time.
The Broadcast
annotation changes this behavior and indicates that messages transiting in the channel are dispatched to all the consumers.
@Broadcast
must be used with the @Outgoing
annotation:
@Incoming("in")
@Outgoing("out")
@Broadcast
public int increment(int i) {
return i + 1;
}
@Incoming("out")
public void consume1(int i) {
//...
}
@Incoming("out")
public void consume2(int i) {
//...
}
In the previous example, both consumers get the messages.
You can also control the number of consumers to wait before starting to dispatch the messages. This allows waiting for the complete graph to be weaved:
@Incoming("in")
@Outgoing("out")
@Broadcast(2)
public int increment(int i) {
return i + 1;
}
@Incoming("out")
public void consume1(int i) {
//...
}
@Incoming("out")
public void consume2(int i) {
//...
}
Inbound connectors also support a broadcast attribute that allows broadcasting the messages to multiple downstream subscribers.
|
Use with Emitter
For details on how to use @Broadcast
with Emitter
see the documentation.