If your event source needs to send multiple events in a batch,
you can improve performance by sending them with a single call to the sendEvents()
method.
Why and when to perform this task
Batching events in this way can also be useful for logical groups
of events that should be sent only if an underlying transaction has completed
successfully. All of the submitted events are sent as part of a single transaction.
Alternatives for this task
- To send multiple events with the current emitter settings, use
the sendEvents(CommonBaseEvent[]) method:
String[] eventIds = emitter.sendEvents(events);
In
this example, emitter is an Emitter instance, and events is
an array of CommonBaseEvent instances.
- To send multiple events and override the current emitter settings,
use the sendEvents(CommonBaseEvent, int, int) method, specifying the synchronization
mode and transaction mode you want to use:
String eventId = emitter.sendEvent(event,
synchronizationMode,
transactionMode);
Result
The returned value, eventIds, is an array containing
the globally unique identifiers of the sent events.
Each event is validated
and checked against the current filter criteria. All of the valid events that
pass the filter criteria are then sent using the appropriate mechanism:
- If you are using synchronous event transport, the events are sent using
a single EJB call. If an error occurs during the EJB call, an exception is
thrown and none of the events are sent.
- If you are using asynchronous event transport, all of the events are sent
using a single JMS message. If an error occurs during JMS processing, an exception
is thrown and none of the events are sent.