CFEventGatewayAdapter and Selectors

Lately I've been doing a lot of work with Flex messaging using ColdFusion and BlazeDS. Recently I was trying to get message filtering working using the Flex Consumer component's selector property. After a few false starts I found that I just couldn't get selectors to work using either BlazeDS or LCDS.

Well, yesterday I got confirmation that the CFEventGatewayAdapter used to by ColdFusion does not support selector evaluation. I'm hoping future releases will support selectors, but for now this means that if you want to do message filtering with ColdFusion you will have to use subtopics.

Using subtopics with either BlazeDS or LCDS takes a little bit of server setup, but not much. Basically you just need to find the messaging-config.xml file in your WEB-INF/flex folder and add the following to your ColdFusionGateway destination properties:

<server>
<allow-subtopics>true</allow-subtopics>
<subtopic-separator>.</subtopic-separator>
</server>

Here is what my destination definition looks like for reference:

<!-- ======================================== -->
<!-- ColdFusion Messaging Gateway -->
<!-- ======================================== -->
<destination id="ColdFusionGateway">
<adapter ref="cfgateway" />
<properties>
<!--
Star ('*') means gatewayid is found in the 'gatewayid' message header.
To restrict this destination to a specific gateway, enter its ID here
-->

<gatewayid>*</gatewayid>

<!--
If ColdFusion is running on a different host, enter that here.
Default is to expect ColdFusion and Flex to share the same web application.
            You must enter 'localhost' if CF and Flex are not in the same web app.
         
<gatewayhost>10.1.1.1</gatewayhost>
-->


<!--
List the IP addresses of CF machines allowed to send messages to this destination
If not set, the default is to allow only this computer to connect.

<allowedIPs>10.1.1.1,10.2.2.2</allowedIPs>
-->


<!--
Credentials to pass along in the headers as CFUsername/CFPassword.
It is generally better to use setRemoteCredentials() API on client.

<remote-username></remote-username>
<remote-password></remote-password>
-->

<!--
You can add general Flex Messaging network and server properties here.
-->


<server>
<allow-subtopics>true</allow-subtopics>
<subtopic-separator>.</subtopic-separator>
</server>

</properties>

      <!-- You should use the ColdFusion specific channels -->
<channels>
<channel ref="cf-polling-amf"/>
</channels>
</destination>

Once that is set up you just need to make sure you define the subtopic header in any messages you produce. From Flex this is easy, just set the subtopic property of your Producer component. In ColdFusion you need to make sure any messages you produce have the DSSubtopic header. For example if I wanted to send a message to the 'Psychocandy' subtopic I would need to do something like the following:

<cfscript>
msg = StructNew();
msg.destination = "ColdFusionGateway";
msg.body = "Just Like Honey";
msg.headers["DSSubtopic"] = "Psychocandy";
SendGatewayMessage("SomeDataServicesMessagingGateway",msg);
</cfscript>

For more info on using subtopics see the BlazeDS and ColdFusion documentation.

Thanks go to Alex Glosband for looking into the CFEventGatewayAdapter and confirming the selector issue I was seeing.

Related Blog Entries

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.