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
<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.


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.
http://www.seegeorgiarealestate.com/Roswell_Georgi...
example on BlazDS?
Thanks
Philip
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?
dumb question but how do we set the destination if we have a bunch of flex apps hitting the sane cf server?
thanks.
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...
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.
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.
I am trying to connect my Flex client to CF without any success. I tried your code and still get the same error.
Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 500: url: 'http://localhost/flex2gateway/cfamfpolling'
Any clue on this one?
Best
Sam
Error invoking CFC for gateway MyMessageTest: Unable to find the Flex adapter for destination ColdFusionGateway in the RMI registry on 127.0.0.1:1099
Don't get why it can't find the CFC, the CFC I defined for my gateway IS running. It seems the message I sent from your Flex code.