MATLAB Examples

Forwarding vs. Sending a Message

This example shows the difference between forwarding a message and resending another message with the same data.

The chart "Producer" outputs a single message at every time step with a constantly increasing data.

These messages are processed by the "Forwarder" chart. Every time step, this chart removes a single message from its input queue.

If the message data is divisible by 2, then it modifies the data of that message and then forwards it along to "Consumer1":

M.data = M.data + 3;
forward(M, Mout1);

If the message data is odd, it creates a new message "Mout2" and sends it to "Consumer2":

Mout2.data = M.data;
send(Mout2);

The difference between forwarding and sending a new message is evident on the Sequence Viewer. When you select the message between "Producer" and "Forwarder" with data 0 (shown with the label "M(0)"), the Sequence Viewer also highlights the message between "Forwarder" and "Consumer1". Notice the hint "2 items" in the top right corner.

On the other hand, if you select "M(1)" between "Producer" and "Forwarder", it is the only message line highlighted because the message with the same data between "Forwarder" and "Consumer2" is an entirely different message.