I am trying to get a working code up that uses Event Sourcing and Retroactive pattern as described by Martin Fowler.
I am a bit lost on how events are queued up ? since events are sent one by one to EventProcessor's process and reverse function . He says in his article that EventProcessor class will have access to the event queue.
but if my/his EventProcessor class looks like this
public class DomainEventProcessor {
public void process(DomainEvent domainEvent) {
if (domainEvent instanceof ReplacementEvent) {
processReplacement((ReplacementEvent)domainEvent);
} else {
domainEvent.process();
}
}
public void reverse(DomainEvent domainEvent) {
domainEvent.reverse();
}
/*
// replace the event in event queue
*/
private void processReplacement(ReplacementEvent e) {
}
}
The domain event interface
public abstract class DomainEvent implements Serializable {
public abstract void process();
public abstract void reverse();
}
an example implementation event looks like this
public class BalanceUpdateEvent extends DomainEvent {
private String subscriberId;
private String balanceId;
private Long delta;
public String getSubscriberId() {
return subscriberId;
}
public String getBalanceId() {
return balanceId;
}
public Long getDelta() {
return delta;
}
@Override
public void process() {
// do nothing
}
@Override
public void reverse() {
SubscriberDomain subscriberDomain = SubscriberAggregate.getSubscriber(subscriberId);
subscriberDomain.handleReverseEvent(this);
}
}
Each event knows which domain object( which has state + business logic) can handle itself to make changes to domain object state.
Aucun commentaire:
Enregistrer un commentaire