Using traceId in metadata to find the associated events


is there a way to find the events which have a particular traceId (using Axon API)? If not, will Axon provide any functionality in the near future to actually query the traceId values in the events/aggregates? E.g. something along the lines “DomainEventStream readEvents(String aggregateIdentifier, … traceId)”.

Use case: we want to annul a particular event in an aggregate A (annulment means essentially an undo of the state change pertaining to that event, of course by issuing a new AnnulmentEvent - that is a functional requirement). That event caused creation of instances of another aggregate B which lead to AggregateBCreatedEvents (even though we do not use Sagas, as the command-event-command-event… chain is completely synchronous). Now the annulment should also annul (delete) all the instances of aggregate B that had been created by it. Those AggregateBCreatedEvents have the same traceId value as the event to be annulled (. That is how they can be found, but using SQL is not very elegant in this case.


Axon isn’t actually aware of any traceId. For Axon, these are just meta-data headers, like any other.
We do have some ideas for opening streams using filters that are evaluated on the event store side (as much as possible). However, support for this would depend on underlying databases, as not all of them support secondary indices based on json/xml field data.

Actually, it should be fairly easy to create your own “index” for this feature. Create an event handler that stores the first TrackingToken as well as the last one for any TraceID that appears. When you want to stream events for a specific traceID, open a stream using the first tracking token. Filter out any events that don’t have the correct trackingID and stop reading when the returned token ‘covers’ the ending token of the traceID.
This approach should work well as a project/application specific solution, but not really as a general solution in the framework.