Is it possible to access the Queue names from the EventMessage using @Metadata? We have a special usecase where we have same event pushed to 2 clusters and need to be processed with minor difference (i.e persist in storeA or storeB) Rest of business logic remains same.
The alternate approach is to have separate eventHandler for each of the Queues. But results in a lot of duplicate classes.
We are setting the Axon.MetaData part of the Cluster configuration. Will that ensure the metadata gets attached in the Eventhandler & accessible via @Metadata parameter? Or do we need to still do anything explicit to get this AMQPConfiguration.queueName accessible in the eventHandler.
this meta data is different from the meta data in events. This one is meant for information about a cluster. The AMQPMessageConverter converts AMQP messages into Axon messages. It’s not unlikely that the queue name is available in one of the headers of the AMQPMessage. If it is, you can put that information in the meta data of the message created by the converter. Then, in your event handlers, you can extract that information and base your logic on it.
The only way i see to wire the queueName to my event is as below:
By extending ClusterMessageListener and overridding onMessage() method. But this pretty much requires duplicating entire listener code. Is there any optimal way to accomplish this? i.e wiring the queueName as a metaData to my eventMessage?
did you check if the queuename is present in the AMQP Message headers? It it’s there, you can customize the MessageConverter instead.
Oh, and instead if instantiating a HashMap, you can also use Collections.singletonMap(“queueName”, configuration.getQueueName());
Beware of “eventMessage.withMetaData(…)” this will overwrite any exiting meta data. Instead, you probably want to use “andMetaData()”.