Event Queue and Message Dispatch
After a subscriber distributes a message to an event queue, the message is ready for processing. But processing does not occur until after the program explicitly dispatches the message from the event queue. Event queues have no analogue in TIBCO EMS.
Event Queue as a Separation
A program that creates subscriber objects must also create at lest one event queue. The program must add each subscriber to an event queue.
Message Events
More precisely, a message event makes a brief stop on an event queue. A message event is a package that includes a message, the appropriate callback method to process the message, and all the arguments that the callback method requires. (This level precision is not important for developers. It is more common to say that the event queue contains messages, even though it actually contains message events.)
Dispatch
The dispatch call removes a message event from an event queue, and invokes the callback method on the message.
Application programs arrange a dispatch thread running a loop that dispatches messages.
It is good practice to dispatch each event queue using at least one dispatch thread. You can even dispatch a queue using several concurrent threads, unless concurrent processing of messages would yield incorrect application semantics.
Key Points for Developers
- A program creates an event queue.
- A program associates each subscriber with one event queue and one message processing callback.
- A program dispatches message events from the event queue for processing.
- Use a dispatch loop to repeatedly dispatch messages.
- You may start several dispatch loops in separate threads to take advantage of multi-core processors.