Subscribing to multiple ActiveMQ topics in a Coldfusion Event Gateway

190 views Asked by At

I was wondering if I could use the Coldfusion example ActiveMQ event gateway to subscribe to multiple topics.

Currently I can set

destinationName=dynamicTopics/topic1

however I would have assumed I could set some kind of Composite Destination

destinationName=dynamicTopics/topic1,topic2

or

destinationName=dynamicTopics/topic1,dynamicTopics/topic2

This does not seem to work. Is this just not possible out of the box, or am I missing something about how JNDI works?

Obviously the alternative is creating multiple event gateways, but I do not like that idea at all.

Also it would be important to have access to the incoming message's topic's name in the onIncomingMessage handler

1

There are 1 answers

0
Brian Ghidinelli On

The way that I accommodate multiple destinations in a single ActiveMQ event gateway is to use an "action" as my qualifier. Rather than have multiple queues or topics, I instead include the target in my payload like:

payload = {action: "notify", foo: "bar"};
sendGatewayMessage('gw', {status = "SEND",
                          topic="dynamicTopics/sync", 
                          message = serializeJson(payload)});

Then in onIncomingMessage, I fork based on the action:

<cffunction name="onIncomingMessage">
    <cfargument name="event" type="struct" required="true" />

    <cfset var msg = deserializeJson(arguments.event.data.msg) />

    <cfif msg.action EQ "verify">
        <cfset verify(argumentCollection = msg) />
    <cfelseif msg.action EQ "notify">
        <cfset notify(argumentCollection = msg) />
    </cfif>

</cffunction>

And I use private methods to implement each of the routines as needed. A bonus of pulling the code out of onIncomingMessage, it can be implemented in a standalone CFC which can be unit tested on its own using something like MxUnit or TestBox.