Home > Articles > Programming

  • Print
  • + Share This
This chapter is from the book

Message Sequence

messagesequence_icon.jpg

Use a Message Sequence when you need to send one logical Message (130) that must be delivered as multiple physical Messages (130). Together all the messages in the sequence form a batch, but the batch is delivered as separate elements. Each Message (130) will have the following:

  • A unique Message Sequence identity, such as a Correlation Identifier (215).
  • A sequence number indicating the sequence of the particular message in the separated batch. The sequence could run from 1 to N or from 0 to N-1, where N is the total number of messages in the batch.
  • Some flag or other indicator of the last message in the batch. This could also be achieved by placing a total on the first message to be sent.

On first considering the way the Actor model messages are sent and received, it may seem unnecessary to use a Message Sequence. Also discussed in Resequencer (264), Akka direct asynchronous messaging has the following characteristics, as applicable in a discussion of Message Sequence (217):

  • Actor Batch-Sender sends messages M1, M2, M3 to Batch-Receiver.

Based on this scenario, you arrive at these facts:

  1. If M1 is delivered, it must be delivered before M2 and M3.
  2. If M2 is delivered, it must be delivered before M3.
  3. Since there is no (default) guaranteed delivery, any of the messages M1, M2, and/or M3, may be dropped, in other words, not arrive at Batch-Receiver.

Although sequencing is not a problem in itself, note that the problem arises if any one message sent from Batch-Sender does not reach Batch-Receiver. Thus, when multiple messages comprising a batch must be delivered to Batch-Receiver for the use case to complete properly, you must assume that Batch-Receiver will be required to interact with Batch-Sender if Batch-Receiver detects missing messages from the batch.

When designing the interactions between Batch-Sender and Batch-Receiver, it may work best to design Batch-Receiver as a Polling Consumer (362). In this case, the Batch-Sender tells the Batch-Receiver that a new batch is available, communicating the specifications of the batch. Then the Batch-Receiver asks for each messages in the batch in order. The Batch-Receiver moves to the next sequence in the batch only once the current message in the sequence is confirmed. The Batch-Receiver can perform retries as needed using schedulers, which is also discussed with regard to Polling Consumer (362).

Otherwise, if the Batch-Sender drives the process by sending the message batch in an enumerated blast, the Batch-Receiver must be prepared to request redelivery for any sequence that it doesn’t receive.

  • + Share This
  • 🔖 Save To Your Account