1 Reply Latest reply on Jun 30, 2009 6:30 AM by Cr99

    BlazeDS with AIR and messaging

    Cr99 Level 1

      In a recent post:

       

      http://forums.adobe.com/thread/450648?tstart=0

       

      I asked about setting up AIR with blazeDS.  Using the link from the previous post, I got it working for remoting ok:

       

      <mx:RemoteObject id="reportRetrieval" destination="reportLoad" channelSet="{amfChannelSet}">

       

      But I can't get it working for messaging.  How do I define destinations (not channels) for AIR at runtime?  In Flex, I just define them in the messaging-config.xml file.  For remoting I define a channel, but for messaging I define a destination.  Here's what I have from the messaging-config file which works in flex:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <service id="message-service"

          class="flex.messaging.services.MessageService">

       

           <adapters>

              <adapter-definition id="TCautomation" class="factory.AutoWatcher"/>

              <adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />

          </adapters>

       

          <default-channels>

              <channel ref="my-polling-amf"/>

          </default-channels>

       

           <destination id="autoWatch">

               <adapter ref="TCautomation"/>

           </destination>

       

      </service>

      And here are my components in mxml:

       

      <mx:Producer id="reportManager" destination="autoWatch"/>

      <mx:Consumer id="consumer" destination="autoWatch" message="messageHandler(event.message)"/>

        • 1. Re: BlazeDS with AIR and messaging
          Cr99 Level 1

          Ok, well I've made some progress.  I can now send messages, but I can't receive them.

           

          Here's how I set it up in actionscript:

           

           

          private var producer:Producer = new Producer();

          private var consumer:Consumer = new Consumer();

          private var blazeUrl:String = "http://localhost:8888/myApp/messagebroker/";

           

           

          public function init():void {

           

           

          var myPollingAMF:AMFChannel = new AMFChannel("my-polling-amf", blazeUrl + "amfpolling");

          myPollingAMF.pollingEnabled = true;

           

          var channelSet:ChannelSet = new ChannelSet();

          channelSet.addChannel(myPollingAMF);

          consumer.channelSet = channelSet;

          producer.channelSet = channelSet;

          consumer.destination = "autoWatch";

          producer.destination = "autoWatch";

          consumer.addEventListener(MessageEvent.MESSAGE, messageHandler);

          consumer.subscribe();

           

          var message:IMessage = new AsyncMessage();

          message.body.command = "message received ???";

          producer.send(message);

          }

           

          // alert never gets fired due to error

          private function messageHandler(message:IMessage):void {

          Alert.show(" MESSAGE delivered");

          }

           

           

          And here is the invoke method in my Java:

           

           

          public Object invoke(Message message) {

           

           

          MessageService  service = (MessageService)getDestination().getService();

          String clientID = UUIDUtils.createUUID();

          Message message = new AsyncMessage();

          message.setDestination("autoWatch");

          message.setClientId(clientID);

          message.setMessageId(UUIDUtils.createUUID());

          message.setTimestamp(System.currentTimeMillis());

          TreeMap <String, String>hMap = new TreeMap<String, String>();

          hMap.put("reportID", "rep1");

          message.setHeaders(hMap);

          message.setBody("msg");

           

           

           

            // the following prints and I turn around and try to communicate

            // with consumer (see actionscript above)

            System.out.println("Messge successfully received");

             try {

                  service.pushMessageToClients(message, false); // fails

             }

             catch (Exception e) {

                 System.out.println("\t PROBLEM SENDING");

                  e.printStackTrace();

             }

           

          return "success";

          }

           

           

          And here is the error I get on the AIR debug side:

           

           

          TypeError: Error #1034: Type Coercion failed: cannot convert mx.messaging.events::MessageEvent@1307ad29 to mx.messaging.messages.IMessage.

          at flash.events::EventDispatcher/dispatchEventFunction()

          at flash.events::EventDispatcher/dispatchEvent()

          at mx.messaging::AbstractConsumer/http://www.adobe.com/2006/flex/mx/internal::messageHandler()[E:\dev\3.0.x\frameworks\proje cts\rpc\src\mx\messaging\AbstractConsumer.as:711]

          at mx.messaging::ConsumerMessageDispatcher/messageHandler()[E:\dev\3.0.x\frameworks\projects \rpc\src\mx\messaging\ConsumerMessageDispatcher.as:251]

          at flash.events::EventDispatcher/dispatchEventFunction()

          at flash.events::EventDispatcher/dispatchEvent()

          at mx.messaging::ChannelSet/messageHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\mes saging\ChannelSet.as:1285]

          at flash.events::EventDispatcher/dispatchEventFunction()

          at flash.events::EventDispatcher/dispatchEvent()

          at PollCommandMessageResponder/resultHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\m essaging\channels\PollingChannel.as:739]

          at mx.messaging::MessageResponder/result()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\messa ging\MessageResponder.as:199]

           

           

           

          Could someone please tell me what I'm doing wrong?  Thanks.