org.axonframework.eventhandling
Class EventTemplate

java.lang.Object
  extended by org.axonframework.eventhandling.EventTemplate

public class EventTemplate
extends Object

Template class that dispatches Events to an EventBus, taking active UnitOfWork into account. When a UnitOfWork is active, the template will ensure correct ordering with any other events published during the course of that UnitOfWork. If no unit of work is active, the Event is published immediately to the Event Bus.

Messages sent with this template will have the current thread's correlation data in its meta data.

The template also allows addition of Meta Data properties to all Events sent through this template.

Since:
2.2
Author:
Allard Buijze
See Also:
CorrelationDataHolder

Constructor Summary
EventTemplate(EventBus eventBus)
          Initialize the template to publish Events through the given eventBus.
EventTemplate(EventBus eventBus, Map<String,?> additionalMetaData)
          Initialize the template to publish Events through the given eventBus.
 
Method Summary
 void publishEvent(Object payload)
          Publishes an event with given payload on the configured Event Bus.
 void publishEvent(Object payload, Map<String,?> metaData)
          Publishes an event with given payload on the configured Event Bus, with given metaData attached.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventTemplate

public EventTemplate(EventBus eventBus)
Initialize the template to publish Events through the given eventBus.

Parameters:
eventBus - The EventBus to publish Event Messages on.

EventTemplate

public EventTemplate(EventBus eventBus,
                     Map<String,?> additionalMetaData)
Initialize the template to publish Events through the given eventBus. The given additionalMetaData is attached to all events published through this instance.

Parameters:
eventBus - The EventBus to publish Event Messages on.
additionalMetaData - The meta data to add to messages sent
Method Detail

publishEvent

public void publishEvent(Object payload)
Publishes an event with given payload on the configured Event Bus.

This method takes into account that a Unit of Work may be active, using that Unit of Work to ensure correct publication of the event.

Parameters:
payload - The payload of the event to publish

publishEvent

public void publishEvent(Object payload,
                         Map<String,?> metaData)
Publishes an event with given payload on the configured Event Bus, with given metaData attached. If meta data is also configured on this template, the given metaData will override any existing entries under the same key.

This method takes into account that a Unit of Work may be active, using that Unit of Work to ensure correct publication of the event.

Parameters:
payload - The payload of the event to publish
metaData - Additional meta data to attach to the event


Copyright © 2010-2016. All Rights Reserved.