You can use an event sequencing qualifier when you need to ensure that events are processed in order and that one event is completely processed before the next one is processed.
Sometimes you need to ensure that the data is processed in order. For example, you want to be sure that an employee record is created before any update event for that employee record is processed. Clients determine the sequence in which events are sent to a component, but controlling the sequence in which clients contribute events to a queue is not always enough. The event that would add a new employee record might process slowly while an update event might go through quickly. You can establish a qualifier for such events to ensure that they will be processed in the order they are received.
When a service receives events, those events join a queue. They are scheduled to be processed in the order they are received, but the runtime environment is a multithread environment. Multiple processes serve the queue, and each process can progress at a different speed, so the events might be processed in an order different from that delivered to the queue. There is a delay between the time that one event is taken off the queue and the corresponding operation on the service is invoked. In that window, the next event might be taken off the queue and its corresponding operation might be invoked. Processing delays could cause the second event to be processed before the first event. When processing sequence is important, you can provide a means to control it with the event sequencing qualifier.
Once you have decided that you need event sequencing qualifiers for a component, you need to plan how you want to use them. First, look at the operations on the interfaces for the component. Identify the operations that you want to include in the sequence. You might find that you need two or more sequences because a component manipulates various kinds of objects. For example, a general hotel component might have one set of operations for booking hotel rooms and another set for booking convention halls.
The group identifies which operations will participate in a sequence. For example, put reserve_hotel_room and clean_hotel_room in one group and put book_convention_hall and set_up_convention_hall in another group, assuming operations on hotel rooms are completely independent from operations on convention halls.
The key identifies the object being manipulated. The keys for the first set of operations are the room numbers, such as 201 (second floor, room 01). The keys for the second set of operations might be room names like "Main ball room" and "West projection room." Once you have identified those properties, you need to add an event sequencing qualifier on all the operations, specifying that key. The instructions below explain how to carry out these tasks.
The event sequencing validator requires events to acquire a lock before they are dispatched to the target component to execute business logic. When the execution of the business logic completes, the event releases the lock. Because one task must complete before the next task can begin, you need to be careful where you apply this feature. Make sure that you are not going to tie up an essential process for an unacceptable time because you have applied sequencing to some situation where events might take a long time to complete.
To establish a sequence for events related to an operation, follow these steps:
Related information