Home > Articles > Programming

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

Event Message


Use an Event Message, as illustrated in Figure 6.3, when other actors need to be notified about something that has just occurred in the actor that produces the event. Generally, a Publish-Subscribe Channel (154) is used to inform interested parties about a given event. Yet, sometimes it may be appropriate to tell a specific actor about an event or tell the specific actor and also publish to an abstract set of subscribers. See also Domain Events as discussed in Implementing Domain-Driven Design [IDDD].

Figure 6.3

Figure 6.3 Using an Event Message, a Publisher may notify multiple Subscriber actors about something that happened in the domain model.

For example, when an OrderProcessor receives a RequestForQuotation message, it dispatches a request to fulfill the quotations to any number of product discounters. As each discounter that chooses to participate responds with a PriceQuote Document Message (204) describing the discount offer, the OrderProcessor sends a PriceQuoteFulfilled Event Message to an Aggregator (257).

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

case class PriceQuoteFulfilled(
    priceQuote: PriceQuote) // Event Message

In this specific case, it is unnecessary to broadcast the event using a Publish-Subscribe Channel (154) because it is specifically the Aggregator (257) that needs to know about the price quote fulfillment. You could have designed the Aggregator (257) to accept a Command Message (202) or a Document Message (204) rather than an Event Message. Yet, the OrderProcessor need not be concerned with how the Aggregator (257) works, only that it will satisfy its contract once it has received some required number of PriceQuoteFulfilled events. Also note that the PriceQuoteFulfilled is a Document Message (204) in that the Event Message packs the small PriceQuote Document Message (204) as the PriceQuoteFulfilled event information.

  • + Share This
  • 🔖 Save To Your Account