Coldfusion 8: Simple messaging example using Messaging Event Gateway

The Messaging Event gateway allow us to recieve/send messages from/to Flex clients. This simple example will provide the necessary code to send messages from Flex to the ColdFusion Event Gateway and recieve it back from it.

You can get the files here

Installation:

Create a new flex project and define it as using LifeCycle Data Services and point it you your ColdFusion webroot ( Multiserver default install is under C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war ). Point your output folder to your webroot (where you deploy your applications) or some subfolder. I deployed to c:\inetpub\wwwroot\samples\ and set the output url to http://localhost/samples.

Go to the CFAdmin and in the EventGateway Instances create a new flex messaging gateway called 'flexmessaging' and point to the provided cfc and start it.

Compile and run the application the application. Try to send messages from each pod.

How does it work?

When you press the send button, that message is built and sent to the ColdFusion gateway. Based on the gatewayid in the headers property, it will deliver the message to the corresponding event gateway. Then, the onIncomingMessage is called and at the end of the function I decided to return the exact same message back to the clients.

Notice that I use return but I could also use the SendGatewayMessage function.

Then all connected clients to that same destination will get the notification and the consumer will dispatch a MessageEvent.

Messages are slow to show up?

Messages will take long to appear since by default, integrated LCDS is configured to only use cf-polling-amf with a poll interval of 8 seconds. You can lower this value

<channel-definition id="cf-polling-amf" class="mx.messaging.channels.AMFChannel">
<endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/cfamfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>true</polling-enabled>
<polling-interval-seconds>1</polling-interval-seconds>
<serialization>
<instantiate-types>false</instantiate-types>
</serialization>
</properties>
</channel-definition>

You can also enable rtmp channel which will provide real data push to the client.

To enable rtmp channel, uncomment under the services-config.xml that channel and in the flex-messaging-config.xml add as first channel

...
<channels>
      <channel ref="cf-rtmp"/>
<channel ref="cf-polling-amf"/>
</channels>
...

You will have to restart the ColdFusion server and then recompile the application.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Hi, I'm behind a firewall, and I'd like to know if the messaging feature will work through RTMP in this scenario, I've heard about rtmp tunneling but i don't know how to use it :-(
# Posted By Jorge Tejada | 8/3/07 4:13 AM
Hi Jorge,
you can take a look in this post from the flexdoc team http://blogs.adobe.com/flexdoc/2007/07/realtime_me... . We don't use it because we deploy in our local intranet.
# Posted By João Fernandes | 8/3/07 5:36 AM
Thanks for the information about the Messaging Event gateway. This will really help us get throught things a little faster than normal.
http://www.seegeorgiarealestate.com/Roswell_Georgi...
# Posted By Drew | 2/27/08 9:49 AM
Thanks for the example, it was really helpful, do you have any
example on BlazDS?

Thanks

Philip
# Posted By Philip Bedi | 3/18/08 7:30 AM
Hi Philip, this sample should work with BlazeDS out of the box since everything related to messaging is the exact same in BlazeDS and LCDS
# Posted By João Fernandes | 3/18/08 7:40 AM
João...

I'm walking through this example and can't get past the Flex project setup. I'm using the following apps:

- ColdFusion 8 installed as multi-server.
- FlexBuilder 3
- BlazeDS installed into the cfusion instance

Here's a shot of the first two steps of the Flex project setup:
http://www.commadelimited.com/uploads/part-01.jpg
http://www.commadelimited.com/uploads/part-02.jpg

When validating the configuration I get the error:
"LiveCycle Data Services is not installed at the specific location"

I double checked ColdFusion Admin > Data & Services > Flex Integration:

- Enable Flash Remoting is checked
- Enable Remote Adobe LiveCycle Data Management access is checked
   - Server identity is set to cfusion
- Selected addresses has 127.0.0.1 as the only IP address listed.

Am I doing something wrong that you can see?
# Posted By Andy Matthews | 3/31/08 3:39 PM
João,

dumb question but how do we set the destination if we have a bunch of flex apps hitting the sane cf server?

thanks.
# Posted By PaulH | 4/8/08 10:12 PM
Paul,

you can define multiple destinations, you are not limited to single messaging destination. You can even create destinations at runtime with the java API like described here http://www.onflexwithcf.org/index.cfm/2007/7/3/Usi...
# Posted By João Fernandes | 4/9/08 2:13 AM
João,

thanks, i *think* i'm starting to catch on, at least from flex to cf (though plain jane remoting will do for 99% of my usage). but still not quite getting cf to flex (use cases are flex handing off a report/data export to cf asynch gateway & cf telling *that* flex client the report/exported data is ready as well as cf broadcasting some change to all flex clients for a given app). any "resources for idiots" on that ;-)

thanks.
# Posted By PaulH | 4/9/08 8:46 AM
Imagine Christophe example http://coenraets.org/blog/2008/04/yahoo-maps-colla... , you could eventually based on each message from the client, intercept the call with CF ( EventGateway ) and notify specific clients with additional data.
# Posted By João Fernandes | 4/9/08 9:01 AM
João, what kind of network impact does this usage have? I'm working on a Flex/AIR app that will run in the system tray/dock and should just be polling for a message to display, and when it gets one, pops up a window on the desktop. I already wrote it up using HTTPService to just check an HTML file on our web server, but I figured 1,000 PCs hitting that server every 60-120 seconds would be unnecessary load. Would the polling in LCDS be less intensive or more intensive?
# Posted By Joshua Curtiss | 4/11/08 11:07 AM
Joshua, polling will always give you better performance comparing to httpService requests because it will use AMFX format while HTTPService will use an URLLoader so the packages will be smaller. Of course you'll have to setup the polling with a similar time. You can also use RTMP ( 2.5.1 and 2.6 ) , NIO StreamingHTTP or NIO Long Polling ( both 2.6 ) wich will only notify clients when new data is available so there isn't unnecessary calls made to the server. Once you get new data, just send a message to the destination and all valid clients will recieve the notification.
# Posted By João Fernandes | 4/11/08 11:32 AM
Joshua...

I JUST completed an app that does exactly the same thing. It's written in HTML/JS and uses BlazeDS for the messaging component. It works great.
# Posted By Andy Matthews | 4/11/08 12:16 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001. Design by dcarter.