I have a central backend and then distributed clients which are themselves an aggregate.
The clients each have a GUID and need to react to some events, I was wondering if there was a way to make sure that a specific client receives the event.
Is there some best practice for this use case?
As additional information, the command itself could be processed from anywhere and it would work without too much issue.
as this question has gone unanswered for some time, I will make an attempt. The thing about events is that they do not contain routing information, which means every event of a given type will always be delivered to all handlers for this type of event. Axon is not designed to route different events of the same type to different event handlers. The event handler, however, is free to choose in which way it needs to react to an event. This means, basically, you have two options:
You can distinguish events destined for different clients at the type level, i.e., use a separate type (e.g., subclass) of event for each client.
Or you can filter the events in the client (either within the event handler or in a message handler interceptor), in each client reacting only to events relevant to this client, and ignoring all others.
Which of these options is more appropriate depends on a few factors, one of which is why you need different clients to handle different events. What is it that distinguishes one client from another? Do they perform different functions? Do they perform the same function in different contexts (e.g., for different users)? Does the central backend know in advance which client needs to react to the event? Do the events really represent something that has happened in the past, or is the intention more to trigger a specific action?
In the latter case, there is also option 3, which is not to model the interaction in terms of events but in terms of more generic messages.
I hope this helps. If you have further questions, it would help if you could share some more details of your use case.
Thanks for your reply, my clients are connected to some hardware in different locations. I explored the solutions you mentioned, but none really were fit.
Let’s say that each hardware instance is represented by an aggregate, so in the end I just ended up sending messages over NATS and using my aggregate to keep up with what was happening over the wire.