How to design event handled by aggregate and saga in spring cloud env?

These days I investigated axon a lot, I found it is really great framework, to implement ES pattern. And I am preparing to use it for our product. But I still have some problems.

Now I have a spring cloud micro service, order service and ticket service, using axon.order aggregate handle order related event, ticket aggregate in ticket service handler the preserve, supply and shipment.

I have a saga class, OrderManagementSaga in order service, to process the ordering. It will create/pay order and dispatch command about ticket supply change, shipment.

My question is how should I design the event(between aggregate and saga) and queue(for 2 services)?

For example, the business process is as below:

  1. order service gets an OrderPayCommand, handled by aggregate, apply an OrderPaidEvent
  2. Order aggregate handled this event, update order status, and publish it into AMQP(but the published event is not used.).
  3. OrderManagementSaga handle this event, dispatch a OrderTicketPreserveCommand.
  4. ticket service gets this command, apply an OrderTicketPreservedEvent, and handled in aggregate.
  5. ticket service publish the OrderTicketPreservedEvent into AMQP.
  6. order service gets this event, trigger saga to process next step.

I want to know what’s the best practice to design the:

  1. events: some events need to be handled in 2 service, like OrderTicketPreservedEvent , it will handled by ticket service and order saga. Should I use different event for this?
  2. queues: I use topic type of AMQP, event in a queue processed by only one service. If I use same event, should I send it to TWO queues?

Hi Mavlarn,

  1. events represent something that happened in the domain. It means they must contain the data necessary to explain what happened. Which components are going to handle this command should not matter (too much). In most cases, you can use these events in multiple handlers. The most important thing to ensure, is that the serialized format of the events (which is produced by your serializers) is a format that all listeners can deal with (especially if some of the handlers aren’t Axon applications).

In case components are considered to be in different bounded contexts, then it is recommended not to (automatically) reuse events. You’d want to be more selective about the information you take across these boundaries.

  1. In AMQP (0.9), you use Exchanges to publish messages and Queues to read them. Each queue will hold one copy of an event. So if you want two applications to read their own copy of an event, you must bind two queues to the exchange you publish events to.

Hope this helps.