Start new tracking event processors in replay mode

Hi,

We had a rather interesting problem today. Although we managed to solve it in another way, I would like to have some input on how to resolve this in general.

We have an event handler responsible for sending mails. In order to send those mails, the handler requires a certain projection (a read model). Said projection is managed by another event handler. Both event handlers are tracking and - as one depends on the other - in the same processing group ordered with Spring’s @Order annotation. So far so good.

As the system is already in production, we have the requirement that the new component should not send mails for those older events. So we used the createHeadToken method for the initial token of the processor. However, this led to a problem. While the mail handler should not handle those older events, the projection managing handler definitely has to. Otherwise we risk that the projection is be incomplete. So our only solution (as far as we could see) was to start with the head token and then - immediately - restart the processing group by resetting the token to the beginning of the event stream (the mail handler was of course annotated with @DisallowReplay). Rather cumbersome.

So our question is: Is there a better solution for such a scenario? Is it maybe possible to start the new event processor in replay mode?

Thank you and best regards

Nils

Hi Nils,

Thank you for reaching out to us with this interesting problem. Your approach to it seems to be the valid one.
In this setup, the mail handler needs to be annotated with @DisallowReplay, exactly as you mentioned.
Then, the processing group should be started with the stream head token as the initial tracking token.
Finally, you can reset the processing group by using ReplayToken at the application startup to hydrate the projection. The token should be initialized with parameters: tokenAtReset = the current head of the stream, startPosition = the tail of the stream. This way, events from the tail to the head of the stream are processed. The mail handler with the @DisallowReplay skips them. After the replay, events are processed as usual.

Best regards,
Michal