My requirement was very simple and common. What i want to do is; i want to configure a ConnectionFactory JNDI Object in Glassfish to manage Active MQ connections that is used by applications which have messaging features.
Of course i googled couple of hours. And i run into very few articles. I was surprised because there is not enough documentation for such kind of common requirement. I tried all tutorials, i did every each step that is stated in those articles but i could not succeed. It is probably because the versions that want to integrate is different from the versions that is mentioned in those articles.
Anyway lets start with downloading components. (I know it is silly to start this article with giving download links because you probably already have one Glassfish and one Active MQ working. That's why you are looking for integration of these two :)))
Glassfish v2.1.1: https://glassfish.dev.java.net/downloads/v2.1.1-final.html
Active MQ 5.0.3 :http://activemq.apache.org/activemq-530-release.html
The links above also includes installation guidelines. I assume that you have Glassfish AS and Active MQ installed and working in your environment. Let's start with defining JNDI Resource to Glassfish:
Go to Active MQ installation root and copy the Resource Adapter into Glassfish Resource Adapters folder: copy %ActiveMQ_ROOT%/lib/optional/activemq-rar-5.3.0.rar into %GLASSFISH_ROOT%/lib/addons/resourceadapters/genericjmsra/ and rename rar file as activemq.rar
Open command prompt and type:
#>cd GLASSFISH_ROOT/bin #/GLASSFISH_ROOT/bin>asadmin create-resource-adapter-config --property SupportsXA=false:RMPolicy=OnePerPhysicalConnection:ProviderIntegrationMode=javabean:ConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory:QueueConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory:TopicConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory:XAConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory:XAQueueConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory:XATopicConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory:UnifiedDestinationClassName=org.apache.activemq.command.ActiveMQDestination:QueueClassName=org.apache.activemq.command.ActiveMQQueue:TopicClassName=org.apache.activemq.command.ActiveMQTopic:ConnectionFactoryProperties=brokerURL\=tcp\://tkvwasp02\:61616:ServerUrl\=tcp\://hostname\:61616:LogLevel=FINE activemq
This command will help you to create and configure a resource adapter. Please be careful that the above command is one single line. And do not delete any '\' char. And be sure that your application server up and running. Now it is time deploy the Active MQ resource adapter that rar file we copied into Glassfish in step1.
Execute the following command: #/GLASSFISH_ROOT/bin>asadmin deploy ../lib/addons/resourceadapters/genericjmsra/activemq.rar
From now on you can do each action by using Glassfish Admin Console. But i think using CLI commands is much faster.
So lets create JNDI Resouces
1-Create Connection Pool : Be careful all command must be a single line.
#/GLASSFISH_ROOT/bin>asadmin create-connector-connection-pool --raname activemq --connectiondefinition javax.jms.QueueConnectionFactory --transactionsupport LocalTransaction MyConnectionFactoryPool
2- Create Connection Factory: Again be careful all command must be a single line.
#/GLASSFISH_ROOT/bin>asadmin create-connector-resource --poolname MyConnectionFactoryPool jms/MyConnectionFactory
3- Finally create Message Destination: Must be single line!!!
#/GLASSFISH_ROOT/bin>asadmin create-admin-object --raname activemq --restype javax.jms.Queue --property PhysicalName\=SampleQueue jms/MyQueue
So THAT IS IT!! Now, to feel safe, restart the application server. For testing purposes write a simple MessageListener if JNDI Resources that you defined above is working.
Cheers.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment