Merge
Experimental
|
By default, messages transiting in a channel can arise from a single producer. Having multiple producers is considered erroneous and is reported at deployment time.
The Merge
annotation changes this behavior and indicates that a channel can have multiple producers.
@Merge
must be used with the @Incoming
annotation:
@Incoming("in1")
@Outgoing("out")
public int increment(int i) {
return i + 1;
}
@Incoming("in2")
@Outgoing("out")
public int multiply(int i) {
return i * 2;
}
@Incoming("out")
@Merge
public void getAll(int i) {
//...
}
In the previous example, the consumer gets all the messages (from both producers).
The @Merge
annotation allows configuring how the incoming messages (from the different producers) are merged into the channel.
The mode
attribute allows configuring this behavior:
-
ONE
picks a single producer, discarding the other producer; -
MERGE
(default) gets all the messages as they come, without any defined order. Messages from different producers may be interleaved. -
CONCAT
concatenates the producers. The messages from one producer are received until the messages from other producers are received.
Outbound connectors also support a merge attribute that allows consuming the messages to multiple upstreams. It will dispatch all the received messages.
|