With BlazeDS/LCDS you can send messages to and receive messages from a server side destination thanks to Messaging Services and their client-side API.
In your messaging configuration you can use a ActionScript Adapter:
<adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
or a JMS Adapter:
<adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/>
that integrates Flex messaging with Java Message Service destinations.
If you don't have JMS or you don't want to use it in your web application you can send messages from Java to Flex in a very simple way.
First of all you should enable the ActionScript adapter and create your destination without additional parameters:
<destination id="actionscriptMessaging">
</destination>
In your Flex application you have your Consumer:
<mx:Consumer id="consumer"
destination="actionscriptMessaging"
message="messageHandler(event);"
fault="faultHandler(event);"/>
that is subscribed to the previous destination so that it can receive messages:
consumer.subscribe();
On the Java side, inside the context of the web application in which LCDS/BlazeDS runs, you can use these lines of codes to send messages to your Flex Consumer:
AsyncMessage msg = new AsyncMessage();
msg.setTimestamp(new Date().getTime());
msg.setClientId("JavaMessageProducer");
msg.setMessageId("JavaMessageId");
//destination configured in messaging-config.xml
msg.setDestination("actionscriptMessaging");
msg.setBody("Message from Java!");
//you can set custom message headers
msg.setHeader("headerParam1", "value1");
msg.setHeader("headerParam2", "value2");
//send message to destination
MessageBroker.getMessageBroker(null).routeMessageToService(msg, null);
This is a solution suitable for uni-directional messaging, if you want to use a bi-directional messaging system it's convenient to use JMS.
Comments (3)
Is it possible to do the same with webORB? is there any example?
thanks
Posted by Jelou | June 15, 2009 3:54 PM
Posted on June 15, 2009 15:54
That was very informative. Is there a way to do bi-directional without using JMS ??
Thanks
KK
Posted by kk | September 24, 2009 2:42 PM
Posted on September 24, 2009 14:42
Thanks! Works like a charm
Posted by Kees van Dieren | January 29, 2010 9:09 AM
Posted on January 29, 2010 09:09