Class SimpleDomainEventPublisher

java.lang.Object
com.reallifedeveloper.common.domain.event.SimpleDomainEventPublisher
All Implemented Interfaces:
DomainEventPublisher

public final class SimpleDomainEventPublisher extends Object implements DomainEventPublisher
A publisher of domain events that holds subscribers in a list. Publishing is handled synchronously; to handle events asynchronously, a subscriber could send a message to a message queue or store the event for later processing.

The idea behind this publisher is that it will be configured once and for all, for example using Spring:

   <bean class="th.co.edge.domain.event.SimpleDomainEventPublisher">
     <constructor-arg>
       <list>
         <bean class="com.foo.FooSubscriber" />
         <bean class="com.foo.BarSubscriber" />
       </list>
     </constructor-arg>
   </bean>
 

The publisher can then be injected in the classes that need to publish events:

   @Autowired
   private DomainEventSubscriber eventSubscriber;
 

Used this way in a normal enterprise application, several threads may call the publish(DomainEvent) method simultaneously, so the subscribers should be thread safe.

Author:
RealLifeDeveloper