So I have a ReST api that has a service injected which then submits a command. Currently, I’m using the callback version of sending commands with the ReST api being asynchronous. This works well.
I’m exploring the scenario where the ReST API can be truly fire and forget - so here’s the flow I’m trying to model the flow:
- User submits POST to /api/greetings
- Controller calls service api which submits a command using the .send(Object) variant
- Return the command id to the client with a 202 Accepted status
- Once command is processed and events raised, event has the command Id as metadata. Event and metadata are pushed over a websocket channel.
For (4), I have hooked up the CommandHandlerInterceptor to copy over the command identifier to the event metadata.
I’m hitting an issue with 3 - basically getting access to the command id after sending the command. I can solve it with introducing a separate commandId property in my commands and having custom interceptor/provider to copy that custom property into the metadata.
Just that it seems like taking a shotgun to kill an ant :). Secondly, the command id etc are not really properties of the domain - it’s infrastructure - so I’d rather not mess my domain for that.
I’ve looked at commandDispatchInterceptors - which will let me modify the command before it gets sent out (and gets a CommandMessage object) but there doesn’t seem a way out other than introducing a commandId attribute in my command object. This gets me almost what I want but I still need to introduce a base class for commands with a commandId attribute.
Is there a way to do this without introducing the base and an extra property in the commands?
I’ve been staring at it for a few hours and not seeing a solution - and so I’m here
Thanks for reading.