<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2009://34.36031-</id>
  <updated>2009-11-21T11:10:29Z</updated>
  <title>Comments for Pushing Data Around With Blaze/LCDS (http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.36031</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=36031" title="Pushing Data Around With Blaze/LCDS" />
    <published>2009-04-22T21:54:37Z</published>
    <updated>2009-04-22T21:54:37Z</updated>
    <title>Pushing Data Around With Blaze/LCDS</title>
    <summary>Here&apos;s a quick tip for working with real time data in Flex applications (in particular Blaze Data Services and LiveCycle Data Services).   LCDS isn&apos;t new by any means, but not everyone uses it on a daily basis.   Here are a few ways that you can push real-time data between the server and client applications.</summary>
    <author>
      <name>Andrew Trice</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[Here's a quick tip for working with real time data in Flex applications (in particular <a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/" target="_blank">Blaze Data Services</a> and <a href="http://www.adobe.com/products/livecycle/dataservices/" target="_blank">LiveCycle Data Services</a>).   LCDS isn't new by any means, but not everyone uses it on a daily basis.   Here are a few ways that you can push real-time data between the server and client applications.
<br/><br/>
First of all, you can send and receive messages using <code>Producer</code> and <code>Consumer</code> objects
<br/><br/>
With your <a target="_blank" href="http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/lcds/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=messaging_framework_2.html">messaging channels configured</a>, Sending data back and forth between two clients is easy.  You send data using a Producer object.   Producers are used to data from Flex client instances into the LCDs/BlazeDS messaging system.  You just need to create an AsynchMessage object and send it to the messaging system using the <code>send()</code> function.  The message data can either be a simple type (string, number), or it can be a complex value-object.   You'll just ned to register classes accordingly to have them handled correctly.   Below is a basic example of sending a message across the real-time messaging system.
<br/><br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> 
<code language="perl">
<pre>
<span class="category1">var</span> messsage:AsyncMessage = <span class="category1">new</span> AsyncMessage( myMessage );
myProducer.<span class="category2">send</span>( <span class="category2">message</span> ) </pre>
</code>
 
</div></div> 

This message will be received by all clients that are subscribed to the same messaging system.
<br/><br/>

Receiving a message from the LCDS system is just as easy.   The difference is that you use a Consumer object to consume data from the messaging system.   With the consumer configured to point at the messaging channel, you just need to add a listener for MessageEvent.MESSAGE events on the consumer object.  These will be dispatched any time that a message is received on the consumer.

<br/><br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> 
<code language="perl">
<pre>
myConsumer.addEventListener( MessageEvent.MESSAGE, onMessage );</pre>
</code>
 
</div></div> 

And you can handle them accordingly on the client side... Whether it is updating a view, displaying an alert, or showing some other kind of interaction.
<br/><br/>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> 
<code language="perl">
<pre>
<span class="category1">private</span> <span class="category1">function</span> onMessage( event : MessageEvent ):<span class="category1">void</span> 
{	
 	<span class="linecomment">//do something now that you have received a message</span>
}</pre>
</code>
 
</div></div> 


Now, this is where things get really interesting... Messages don't always have to originate from a Flex client to be received by other Flex clients.    Messages can originate in a java process and be pushed to subscribed clients.   The following code will enable you to send a message originating in the java server tier to those subscribed client machines.
<br/><br/>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> 
<code language="perl">
<pre>
<span class="linecomment">//create a new message</span>
AsyncMessage <span class="category2">message</span> = <span class="category1">new</span> AsyncMessage();

<span class="linecomment">//should be a unique id that identifies the message origin (commonly a GUID)</span>
<span class="category2">message</span>.setClientId( myClientId );  

<span class="linecomment">//set the destination -- this should match the </span>
<span class="linecomment">//messaging destination id in messaging-config.xml</span>
<span class="category2">message</span>.setDestination( "<span class="quote">myDestination</span>" );

<span class="linecomment">//set a unique message id and timestamp</span>
<span class="category2">message</span>.setMessageId( UUIDUtils.createUUID(<span class="category1">false</span>) );
<span class="category2">message</span>.setTimestamp( <span class="category2">System</span>.currentTimeMillis() );

<span class="linecomment">//set the content of the message - can be an object or a string</span>
<span class="category2">message</span>.setBody( messageContent );  

<span class="linecomment">//send the message to subscribed clients</span>
MessageBroker.getMessageBroker(<span class="category1">null</span>).routeMessageToService(msg, <span class="category1">null</span>);</pre>
</code>
 
</div></div> 

This kind of setup can be used in a variety of ways... broadcast messages server processes, having a service invocation dispatch data synchronization or status messages, having a rpc service stream data back to a client, among many other scenarios.   This technique is extremely useful.

<br/><br/>


___________________________________<br/>
<strong>Andrew Trice</strong><br/>
Principal Architect<br/>
<a href="http://www.cynergysystems.com" target="_blank">Cynergy Systems<br/>
http://www.cynergysystems.com</a>

]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36031-comment:2058141</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36031" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html#comment-2058141" />
    <title>Comment from Joel on 2009-04-22</title>
    <author>
        <name>Joel</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi Andrew,</p>

<p>Can BlazeDS/LCDS converse with JMS via other J2EE applications in the same container? Like say I have a REST api that a user updates from a device/site, could that action notify my AMF clients that an update has occurred?</p>]]>
    </content>
    <published>2009-04-23T04:48:09Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36031-comment:2058164</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36031" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html#comment-2058164" />
    <title>Comment from Dane on 2009-04-23</title>
    <author>
        <name>Dane</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Nice summary. Do you know if the code to send messages originating on the server also be done in ColdFusion in a similar manner? <br />
</p>]]>
    </content>
    <published>2009-04-23T13:20:47Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36031-comment:2058226</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36031" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html#comment-2058226" />
    <title>Comment from Andrew Trice on 2009-04-23</title>
    <author>
        <name>Andrew Trice</name>
        <uri>http://www.tricedesigns.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.tricedesigns.com">
        <![CDATA[<p>Joel,   Yes, you can configure LCDS to communicate with JMS channels.  I haven't played with those much, but I do know that it is possible.   However, it also depends what you mean by "AMF clients".  If you are using AMF as a polling mechansim in LCDS or Blaze DS, then yes.  However if you are only using AMF remoting/serialization (no messaging), then no you can't.</p>

<p>Dane,  Yes, you have to use the CF Event Gateway Adapter to send messages from CF to LCDS/BlazeDS.  I haven't tried this in a few years... but if I remember correctly, there are a few gotchas if you are trying to do subtopic or selector based filtering of messages sent using the CF event gateway</p>]]>
    </content>
    <published>2009-04-23T21:19:55Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36031-comment:2058484</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36031" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html#comment-2058484" />
    <title>Comment from Oussama on 2009-04-28</title>
    <author>
        <name>Oussama</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Nice work.<br />
I work actually on a data push application using flex and java.<br />
I've tested many examples to use messaging service in BlazeDS.<br />
Every time a null pointer exception is occuried when I want to instanciate a "MessageBroker" to route message to destination as you have written in the article.<br />
I don't know if I should specify an adapter to have a working sample??</p>]]>
    </content>
    <published>2009-04-28T13:10:56Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36031-comment:2058485</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36031" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html#comment-2058485" />
    <title>Comment from Andrew Trice on 2009-04-28</title>
    <author>
        <name>Andrew Trice</name>
        <uri>http://www.tricedesigns.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.tricedesigns.com">
        <![CDATA[<p>Make sure you have your messaging destination and messaging channels defined properly.  If you have more than one destination, you might need to access the destination by name/id, instead of just calling getMessageBroker with a null parameter.</p>]]>
    </content>
    <published>2009-04-28T13:35:56Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36031-comment:2058824</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36031" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/pushing-data-around-with-blaze.html#comment-2058824" />
    <title>Comment from Oussama on 2009-05-04</title>
    <author>
        <name>Oussama</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>In fact I think that there is a problem with MessageBrokerServlet.<br />
I got an aphache error message like this:<br />
INFO: La servlet MessageBrokerServlet est marqué comme indisponible<br />
4 mai 2009 10:00:18 org.apache.catalina.core.StandardContext loadOnStartup<br />
GRAVE: La servlet /BlazeDS_GoogleChart a généré une exception "load()"<br />
javax.servlet.UnavailableException: com/espertech/esper/client/UpdateListener<br />
	at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:170)<br />
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)<br />
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)<br />
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)<br />
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)<br />
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)<br />
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)<br />
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)<br />
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)<br />
	at org.apache.catalina.core.StandardService.start(StandardService.java:516)<br />
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)<br />
	at org.apache.catalina.startup.Catalina.start(Catalina.java:566)<br />
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br />
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)<br />
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)<br />
	at java.lang.reflect.Method.invoke(Unknown Source)<br />
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)<br />
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)</p>]]>
    </content>
    <published>2009-05-04T08:05:33Z</published>
  </entry>

</feed
