4 Replies Latest reply on Sep 12, 2009 10:46 AM by PENNY506

    Problem with Flex Messaging using JMS

    itz_Kumar
      Hi Friends,

      I have started working on flex recently and got problem while implementing Flex Chat application using JMS adaptor. I was able to successed making it work with Flex Action Script, but I need have my chat application with JMS. Here I am posting the details about how I have done the chat application for JMS.

      I am using Tomcat 5.5.25, Flex 2 and ActiveMQ 4.4 M4.

      my WEB-INF/flex/messaging-config.xml with destination as
      ........
      <adapters>
      <adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter" default="true"/>
      </adapters>
      ........

      <destination id="chat-topic-jms">

      <properties>

      <server>
      <durable>false</durable>
      <durable-store-manager>flex.messaging.durability.FileStoreManager</durable-store-manager>
      </server>

      <jms>
      <destination-type>Topic</destination-type>
      <message-type>javax.jms.ObjectMessage</message-type>
      <connection-factory>topicConnectionFactory</connection-factory>
      <destination-jndi-name>FlexChatTopic</destination-jndi-name>
      <durable-consumers>false</durable-consumers>
      <delivery-mode>NON_PERSISTENT</delivery-mode>
      <message-priority>DEFAULT_PRIORITY</message-priority>
      <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
      <transacted-sessions>false</transacted-sessions>
      <initial-context-environment>
      <property>
      <name>java.naming.factory.initial</name>
      <value>org.apache.activemq.jndi.ActiveMQInitialContextFactory</value>
      </property>
      <property>
      <name>java.naming.provider.url</name>
      <value>tcp://localhost:61616</value>
      </property>
      </initial-context-environment>
      </jms>
      </properties>

      <channels>
      <channel ref="my-rtmp"/>
      </channels>

      <adapter ref="jms"/>

      </destination>
      ................

      my WEB-INF/classes/jndi.properties file

      java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory

      # use the following property to configure the default connector
      java.naming.provider.url = tcp://localhost:61616

      # use the following property to specify a class path resource or URL
      # used to configure an embedded broker using the XML configuration file
      #brokerXmlConfig = file:src/conf/sample-conf/default.xml

      # use the following property to specify the JNDI name the connection factory
      # should appear as.
      connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactory

      # register some queues in JNDI using the form
      # queue.[jndiName] = [physicalName]
      # queue.MyQueue = example.MyQueue


      # register some topics in JNDI using the form
      # topic.[jndiName] = [physicalName]
      # topic.MyTopic = example.MyTopic
      topic.FlexChatTopic = chat.Topic
      ................................................

      in my web.xml file I have added

      <listener>
      <listener-class>com.silverisland.servlet.listener.ActiveMQBrokerStartListener</listener-c lass>
      </listener>

      finally my mxml file

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      creationComplete="consumer.subscribe()">

      <mx:Script>
      <![CDATA[

      import mx.messaging.messages.AsyncMessage;
      import mx.messaging.messages.IMessage;
      import mx.controls.Alert;

      private function send():void
      {
      var message:IMessage = new AsyncMessage();
      Alert.show("msg dst >> "+message.toString());
      message.body.chatMessage = msg.text;
      producer.send(message);
      msg.text = "";
      }

      private function messageHandler(message:IMessage):void
      {
      Alert.show("msg recived >> "+log.text);
      log.text += message.body.chatMessage + "\n";
      }

      ]]>
      </mx:Script>

      <mx:Producer id="producer" destination="chat-topic-jms"/>
      <mx:Consumer id="consumer" destination="chat-topic-jms" message="messageHandler(event.message)"/>

      <mx:Panel title="Chat" width="100%" height="100%">
      <mx:TextArea id="log" width="100%" height="100%"/>
      <mx:ControlBar>
      <mx:TextInput id="msg" width="100%" enter="send()"/>
      <mx:Button label="Send" click="send()"/>
      </mx:ControlBar>
      </mx:Panel>

      </mx:Application>

      Please help me.
      Thanks in advance

      Regards,
      Kumar

        • 1. Re: Problem with Flex Messaging using JMS
          Mete Atamel Level 1
          What exactly is the problem? Turn on debug logging on the server and let us know if you see any exceptions/errors.
          • 2. Re: Problem with Flex Messaging using JMS
            itz_Kumar Level 1
            Hi Mete Atamel,

            The problem here is I am not able to send the message to the server. There is no error / exception raised.

            The same code is working fine when I was using "Flex Messaging service" with the following changes.

            my WEB-INF/flex/messaging-config.xml with destination as
            ..............................
            <adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
            ............................................

            <destination id="chat-topic-jms">

            <properties>
            <network>
            <session-timeout>0</session-timeout>
            </network>
            <server>
            <max-cache-size>1000</max-cache-size>
            <message-time-to-live>0</message-time-to-live>
            <durable>false</durable>
            </server>
            </properties>

            <channels>
            <channel ref="my-rtmp"/>
            </channels>

            </destination>
            --------------------------------------------------------------

            But when I changed the same code to make it work for JMS adapter, it is not even sending the message to the server itself. I was not able to understand the actual problem. Can u please tell me where I was going wrong.

            Thanks in advance.

            Regards,
            Kumar
            • 3. Re: Problem with Flex Messaging using JMS
              Mete Atamel Level 1
              It's hard to tell what might be wrong. You should turn on server side debug logging on. Look into services-config.xml, there's a logging section. Make sure the level is set to "Debug", run your test again and see what server side logging you get. If you cannot send messages, there should be more info in the debug log for why that is happening.
              • 4. Re: Problem with Flex Messaging using JMS
                PENNY506

                Did you ever get this working?  I'm attempting to do a similar thing with Jrun4 -

                There is a good article here that might help as your configuration is similar.