How to ensure that the event handling components will receive and process events in the order they have been persisted in the eventstore

If the entire stream needs to be in order, then processing all events with one segment would indeed be your only solution. There are, roughly speaking, three options you have.
Let me share those:

  1. You can change the SequencingPolicy from the default SequentialPerAggregatePolicy to SequentialPolicy. This works, but would still mean you have two segments, of which one doesn’t do a thing.
  2. Stop your application(s), clear out the token and construct a new entry yourself with the right segment id. This would require some insight in how to insert such an entry though, as well as that both your segments should be at the exact same position for this to work. Otherwise, you’d need a token that can point to two positions in the stream.
  3. You should merge the segments of your TrackingEventProcessor into one another. This is what Axon Framework has the split and merge operation for, with the following documentation. Quite recently some people at AxonIQ have written a detailed blog about it too, which you can find here.

Although option 1 works, I feel option 2 to be the cleaner approach. Option two will essentially clear out the unnecessary token entirely, thus minimizing the resources used by said TrackingEventProcessor. To invoke the merge operation, you should thus first get hold of the TrackingEventProcessor you need to merge for.

This can be achieved through the EventProcessingConfiguration#eventProcessor(String, Class<?>) method. The String should contain your TEP’s name, and the Class<?> should be TrackingEventProcessor.class. Doing this, you get an Optional<TrackingEventProcessor>, and thus opening up the TrackingEventProcessor#mergeSegment(int) method. Invoking this method with segmentId 0 should do the trick since you only have two segments that take up segmentId 0 and `.

When invoking the mergeSegment operation, you should be aware that the TEP this operation is performed on is required to hold a claim on both segments which you’re merging. If it doesn’t hold the claim or cannot claim either of them, the operation will fail. Thus, the easiest way to ensure this is to only have a single of these TEPs instances running, also in a distributed environment. Doing so will make sure the only running TEP has both claims and as such it can be the place where you’d invoke the mergeSegment() method.

By the way, all this can be done out of the box with Axon Server, as it would know which TEP to invoke the operation on for you. It similarly allows the splitSegment method, in essence giving you the option to scale the number of parallel processes of your event processor as the need arises. As I believe you are not using Axon Server, however, you will have to go through this process of constructing an (end)point through which to invoke this operation on a running instance.

Hope this clarifies your options @Ashwini_Kumar.