Saga Tracking Token always initialized with latest globalIndex


I am running into an issue I could not really explain:
I am running two services. Service A is publishing an event, Service B should react to it by consuming that event inside a SagaEventHandler starting a Saga, ofc annotated with StartSaga.

I am starting Service A and produce some events that should be consumed by Service B. After doing so I start up service B, resulting in Service B not starting any Sagas, not consuming the events from the Axon Server EventStore. The Token for the Saga is set to the latest globalIndex.

My expectation was that Service B would start at index 0 and starting all the work laying around in the EventStore resulting in new Sagas that send new commands resulting in new events and so on.

I am using Axon Framework 4.5.x and the corresponding Axon Server.

Any ideas for me?

Okay, replying to my own thread is lame somehow…:slight_smile:
Anyways, I was able to find it out myself.
The reason for this is wanted behaviour of SagaTrackingEventProcessors as stated in the documentation (so note to myself: RTFM).

A Saga’s Streaming Processor initial position

A Streaming Processor dedicated to a Saga will default the initial token to the head of the stream. The default initial token position ensures that the Saga does not react to events from the past, as in most cases, this would introduce unwanted side effects.

So the only assistance I could need on my way is the following:

  • How would I be able to start from the tail of the stream when I start my Service B for the very first time, or so to say when there is not token for my Saga present inside the TokenStore?
1 Like

Aaaand, found the solution for this one as well.
Had to create a corresponding configuration to set the initial token to tail. Worked like a charm and did exactly what I wanted: Start at index 0 at first startup, Keep the token position when shut down and started again.

1 Like

You are correct here @BKlaus !

By default:

  • A new Event Processor (Processing Group) will always start from the tail, meaning it will process all the past events.
  • A new Saga Processor will always start from head, meaning it wont process past events.

You can easily change it through configuration though and I believe you already found the solution to it! =)