How to send custom metadata through gateways?

I’m using Axon 4.3.1 with AxonServer.

I would like to be able to send metadata on the query and command gateways without using interceptors.

For the command gateway it seems as it is enough to create GenericCommandMessage with the constructor that accepts metadata as a Map.
I’m not completely sure if this is correct, but it looks like it works. However, I believe that the command gateway’s API misses some convenient methods
for doing this without the need for creating GenericCommandMessage.

For query gateway, I didn’t found a way for sending custom metadata. Is it possible currently? Similarily as for command gateway, I think some
convenient methods for sending metadata would be very useful.

Damir Murat

Ok, I found it how to send metadata via queryGateway too. One need to use “<R, Q> CompletableFuture query(String queryName, Q query, ResponseType responseType);” method on QueryGateway where “query” can be GenericMessage containing initial metadata.
Still, I found it rather cumbersome and certainly could benefit from a more easier API.

Damir Murat

Hi Damir,

Thanks for voicing your concern here.
Indeed, it might not be overly evident how this works out of the box.
We’ll take note to figure out a nicer API at some point.

Reasoning behind it currently is that the GenericeQueryMessage not only contains the payload, but also the response type, which as you notice is also part of the API of the QueryGateway.
Essentially you can provide a GenericeQueryMessage containing your own MetaData to the QueryGateway, but it allows for differing ResponseType instances provided in the message and on the gateway.
Hence why the gateway checks for GenericMessage instead, allowing you the same capabilities as on the CommandGateway, albeit slightly less clear.


Steven van Beelen

Axon Framework Lead Developer