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-class>
</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