Home > Articles > Programming

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

Correlation Identifier

correlationIdentifier_icon.jpg

Establish a Correlation Identifier to allow requestor and replier actors to associate a reply message with a specific, originating request message. The unique identifier must be associated with both the message sent by the requestor and the message sent by the replier, as shown in Figure 6.6.

Figure 6.6

Figure 6.6 A Requestor attaches a Correlation Identifier to outgoing Messages (130) in order for the Replier to associate its replies with the originating Message.

In its discussion of Correlation Identifier, Enterprise Integration Patterns [EIP] suggests creating an independent, unique message identifier on the request message and then using that message identifier as the Correlation Identifier in the reply message. The unique message identifier would generally be generated by the messaging system and would be attached only to the message header. Additionally, Enterprise Integration Patterns [EIP] suggests setting the identifier as the request ID on the request message but to be named correlation ID on the reply message.

In principle this is also what is done with the Actor model. Yet, modeling messages for use with the Actor model works a bit differently as well. For example, there is no separate message header, unless one is created as part of the message’s type. Thus, it makes more sense to design message types to contain unique business identities. In this case, you would not need to name the identifier using different names on each message type. In fact, it would most often be best to name the identifier the same on all message types that contain it. That way, it’s just a unique identity that is business specific.

Each of the following message types are correlated using the rfqId (request for quotation ID):

case class RequestPriceQuote(
    rfqId: String,
    itemId: String,
    retailPrice: Double,
    orderTotalRetailPrice: Double)

case class PriceQuote(
    quoterId: String,
    rfqId: String,
    itemId: String,
    retailPrice: Double,
    discountPrice: Double)

case class PriceQuoteTimedOut(rfqId: String)
case class RequiredPriceQuotesForFulfillment(
    rfqId: String,
    quotesRequested: Int)

case class QuotationFulfillment(
    rfqId: String,
    quotesRequested: Int,
    priceQuotes: Seq[PriceQuote],
    requester: ActorRef)

case class BestPriceQuotation(
    rfqId: String,
    priceQuotes: Seq[PriceQuote])

Although Enterprise Integration Patterns [EIP] focuses on the use of Correlation Identifier with Request-Reply (209), there is no reason to limit its use to that pattern. For example, you should associate a Correlation Identifier as a unique business identity with all messages involved in a long-running process [IDDD], whether using ad hock process management or a formal Process Manager (292).

  • + Share This
  • 🔖 Save To Your Account