<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CarbonRider &#187; Blaze DS</title>
	<atom:link href="http://www.carbonrider.com/tag/blaze-ds/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.carbonrider.com</link>
	<description>You make a matrix, you define the limits.</description>
	<lastBuildDate>Thu, 19 Jan 2012 04:35:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spring JMS API, JBoss MQ, BlazeDS &amp; Flex</title>
		<link>http://flex.carbonrider.com/2009/10/03/spring-jms-api-and-jboss-mq/</link>
		<comments>http://flex.carbonrider.com/2009/10/03/spring-jms-api-and-jboss-mq/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 15:34:37 +0000</pubDate>
		<dc:creator>Carbon Rider</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Blaze DS]]></category>
		<category><![CDATA[Flex Chatting]]></category>
		<category><![CDATA[Flex Messaging]]></category>
		<category><![CDATA[JBoss MQ]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring Integration]]></category>

		<guid isPermaLink="false">http://www.carbonrider.com/?p=122</guid>
		<description><![CDATA[This time one more assignment to integrate Spring APIs with Jboss MQ. After reading through Spring documentation, I found its pretty easy to integrate any Messaging Provider solution into Spring application. Configuring JMS Topic in JBoss To create new JMS Topic destination you should configure new topic destination in [deploy_directory]/deploy/jms/jbossmq-destinations-service.xml. Following code snippet creates new [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fflex.carbonrider.com%2F2009%2F10%2F03%2Fspring-jms-api-and-jboss-mq%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fflex.carbonrider.com%2F2009%2F10%2F03%2Fspring-jms-api-and-jboss-mq%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This time one more assignment to integrate Spring APIs with Jboss MQ. After reading through Spring documentation, I found its pretty easy to integrate any Messaging Provider solution into Spring application.</p>
<p><strong>Configuring JMS Topic in JBoss</strong></p>
<p>To create new JMS Topic destination you should configure new topic destination in [deploy_directory]/deploy/jms/jbossmq-destinations-service.xml. Following code snippet creates new Topic Destination.</p>
<p><span id="more-122"></span></p>
<pre name="code" class="xml">
<mbean code="org.jboss.mq.server.jmx.Topic" name="jboss.mq.destination:service=Topic,name=MyTopic">
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
<depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
<attribute name="SecurityConf">
<security>
<role name="guest" read="true" write="true" create="true"/>
</security>
</attribute>
</mbean>
</pre>
<p>Well in actual production system you should not configure guest role access with Read/write permission. Add above XML code snippet below &lt;server&gt; tag and save it. Start JBoss console and you should notice that JBoss will create new topic and bind it to JNDI with name as &#8220;topic/MyTopic&#8221; (Note this is generic JMS client configuration and doesn&#8217;t use any properitory JMS provider APIs. You will have to change the properties of jndiTemplate based on your Messaging Service Provider.)</p>
<p><strong>Using Spring API</strong></p>
<p>Now lets create client code to send messages. I assume that you are using Spring &#8211; BlazeDs integration project and aware of how to configure Spring configuration file with BlazeDS. The following code snippet must be defined in Spring configuration file. Make sure you have also imported Spring-Flex namespace.</p>
<pre  name="code" class="xml">
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="java.naming.provider.url">localhost</prop>
<prop key="java.naming.factory.url.pkgs"> org.jnp.interfaces:org.jboss.naming </prop>
</props>
</property>
</bean>
</pre>
<pre name="code" class="xml">
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName">
<value>java:/XAConnectionFactory</value>
</property>
</bean>
</pre>
<pre name="code" class="xml">
<bean id="jmsDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate"><ref bean="jndiTemplate"/></property>
<property name="jndiName"><value>topic/MyTopic</value></property>
</bean>
</pre>
<p>Now you can expose jmsDestination using flex:jms-message-destination tag. (Available with Spring-BlazeDS integration jar.)</p>
<pre name="code" class="xml">
<flex:jms-message-destination id="my-topic-jms"  jms-destination="jmsDestination" />
</pre>
<p><strong>Creating Flex Client</strong></p>
<p>We are done with the server side configuration and now its time to define Flex Client to subscribe to JMS topic. Flex comes with a handy tag as MX:Consumer and MX:Producer. MX:Consumer is useful to subscribe to JMS topics and queues, while MX:Producer by the name itself it is quite clear that this tag is used to publish messages to JMS. Declare following tag to subscribe to JMS topic</p>
<pre name="code" class="xml">
<mx:Consumer destination="my-topic-jms" id="messageConsumer" message="consumerMessageHandler(event)" fault="faultHandler(event)"/>
</pre>
<p>Note that in above example the value of destination attribute is exactly same as the value of id attribute defined for jms-message-destination tag. This still won&#8217;t start subscription to JMS topic and in order to start subscription you must explicitly subscribe to JMS topic by calling subscribe method  on MX:Consumer instance. Let assume that following function is invoked on &#8220;CreationComplete&#8221; event of application.</p>
<p>private function subscribeTopic():void<br />
{<br />
messageConsumer.subscribe();<br />
}</p>
<p>This will start subscription to JMS topic destination and keep on polling to message server for any new message. OK! but how you will receive message notification, notice there are two event handler defined with MX:Consumer tag declaration. And here is the code snippet of &#8220;message&#8221; event handler.</p>
<p>private function consumerMessageHandler(event:MessageEvent):void<br />
{</p>
<p>var msg:AsyncMessage = new AsyncMessage(event.message);<br />
Alert.show(ObjectUtil.toString(msg.body));<br />
}</p>
<p>This function just prints all the contents of the Message. If you are accessing Object style JMS message, the properties of such message can be accessed using &#8220;.&#8221; notation.</p>
<p><strong>Deployment</strong></p>
<p>Package all the generated SWFs and copy all the required files (JAR, XML configuration files etc) to a WAR file and deploy it on JBoss server. Hit your application URL and you should be able to receive any messages sent to JMS topic.</p>
<p><strong>Known Issue</strong></p>
<p>At the time of deployment, you might come across following exception being thrown by JBoss</p>
<p>: Failed to convert property value of type [org.jboss.mq.SpyXAConnectionFactory] to required type [javax.jms.ConnectionFactory] for property &#8216;connectionFactory&#8217;</p>
<p>Make sure that the deployed WAR file doesn&#8217;t contain and JMS-API library file. The above error is occurring due to ClassLoader issue but the error message is misleading.</p>
]]></content:encoded>
			<wfw:commentRss>http://flex.carbonrider.com/2009/10/03/spring-jms-api-and-jboss-mq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

