RabbitMQ Queue names in @Metadata

Hi,

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.

Thanks,
Jebu.

Hi,

you can probably do that by wrapping the AMQPMessageConverter with a version that adds this to the message’s meta data.

Cheers,

Allard

Allard,

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.

Sample Config below

<axon:cluster id="cluster">
    <axon:meta-data>
        <entry key="AMQP.Config">
            <bean class="org.axonframework.eventhandling.amqp.spring.SpringAMQPConsumerConfiguration">
                <property name="queueName" ref="clusterQueueName"/>
                <property name="exclusive" value="true"/>
            </bean>
        </entry>
    </axon:meta-data>
    <bean class="org.axonframework.eventhandling.async.AsynchronousCluster">
        <constructor-arg value="clusterPrimary"/>
        <constructor-arg ref="asyncExecutor"/>
        <constructor-arg>
            <bean class="org.axonframework.eventhandling.async.FullConcurrencyPolicy"/>
        </constructor-arg>
    </bean>
    <axon:selectors>
        <axon:class-name-matches  pattern="com.foo.*"/>
    </axon:selectors>
</axon:cluster>

Thanks,
Jebu.

Hi,

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.

Kind regards,

Allard

Hi,

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?

`

for (Cluster cluster : clusters) {
    Map<String, String> customMetaData = new HashMap<>();
    SpringAMQPConsumerConfiguration configuration =
            (SpringAMQPConsumerConfiguration) cluster.getMetaData().getProperty("AMQP.Config");
    customMetaData.put("queueName", configuration.getQueueName());
    eventMessage.withMetaData(customMetaData);
    cluster.publish(eventMessage);

}
`

Thanks,
Jebu.

Hi,

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()”.

Cheers,

Allard