Wednesday, May 27, 2015

JBoss FSW Connect ActiveMQ Using ActiveMQ Resource Adapter

Introduction

In order to use external ActiveMQ as message broker, we have install and configure ActiveMQ resource adapter. The resource adapters are the plug-ins for JEE containers. They facilitate the communicates between JEE container and external brokers, databases, etc.

In this post, I am going to demonstrate in details about how to setup and test the ActiveMQ resource adapter. I use my local environment to setup SSL connection to my local ActiveMQ instance.

Install ActiveMQ Resource Adaptoer activemq-rar.rar

Download activemq-rar

activemq-rar (version 5.11.1) file is available at http://mvnrepository.com/artifact/org.apache.activemq/activemq-rar/5.11.1. If you need older version, you can brower the maven repo, and download it accordingly.

Install activemq-rar

  • copy activemq-rar-5.11.1.rar to $JBOSS_FSW_HOME/standalone/deployments
  • mv activemq-rar-5.11.1.rar activemq-rar.rar

Modify JBoss FSW Configuration Files

Here is configuration change on standalone.xml. If you use standalone-full.xml or standalone-fule-ha.xml, do the same.

        
            
                
                    
                        activemq-rar.rar 
                    
                    NoTransaction
                    
                        admin 
                    
                    
                        admin
                    
                    
                        ssl://localhost:61617?jms.rmIdFromConnectionId=true
                    
                    
                        
                            
                                false
                            
                            
                                
                            
                        
                    
                    
                        
                            
                                ServiceGaryQueue
                            
                        
                        
                            
                                ServiceGaryTopic
                            
                        
                    
                
            
        

Another section needs to change is the following:

            
                
                
            

Import ActiveMQ Public Keystore

If you use tcp, there is no need to import certs. However in the enterprise application, nio+ssl is preferred. Thus, we need to perform the following step:

   sudo keytool -import -alias Guojiangs-MacBook-Pro.local \
      -file Guojiangs-MacBook-Pro.local_cert \
      -keystore /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/security/cacerts 

Where Guojiangs-MacBook-Pro.local_cert is public key for the activemq. For how to setup SSL for ActiveMQ, you can refer my blogs: http://ggl-consulting.blogspot.com/2015/03/broker-to-broker-network-connector-with.html

Test The Configuration

First start JBoss FSW without start ActiveMQ. In such a way, we can see the features of automatic reconnection from JBoss FSW.

cd $JBOSS_FSW_HOME/bin
./standalone.sh
12:22:23,724 ERROR [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-threads - 2) Failed to connect to broker [ssl://localhost:61617?jms.rmIdFromConnectionId=true]: Could not connect to broker URL: ssl://localhost:61617. Reason: java.net.ConnectException: Connection refused: javax.jms.JMSException: Could not connect to broker URL: ssl://localhost:61617. Reason: java.net.ConnectException: Connection refused
	at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:360) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:253) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.ra.ActiveMQResourceAdapter.makeConnection(ActiveMQResourceAdapter.java:136) [activemq-ra-5.11.1.jar:5.11.1]
	at org.apache.activemq.ra.ActiveMQEndpointWorker$1.run(ActiveMQEndpointWorker.java:109) [activemq-ra-5.11.1.jar:5.11.1]
	at org.jboss.jca.core.workmanager.WorkWrapper.run(WorkWrapper.java:218) [ironjacamar-core-impl-1.0.19.Final-redhat-2.jar:1.0.19.Final-redhat-2]
	at org.jboss.threads.SimpleDirectExecutor.execute(SimpleDirectExecutor.java:33)
	at org.jboss.threads.QueueExecutor.runTask(QueueExecutor.java:806)
	at org.jboss.threads.QueueExecutor.access$100(QueueExecutor.java:45)
	at org.jboss.threads.QueueExecutor$Worker.run(QueueExecutor.java:826)
	at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_75]
	at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: java.net.ConnectException: Connection refused
	at java.net.PlainSocketImpl.socketConnect(Native Method) [rt.jar:1.7.0_75]
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) [rt.jar:1.7.0_75]
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) [rt.jar:1.7.0_75]
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) [rt.jar:1.7.0_75]
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) [rt.jar:1.7.0_75]
	at java.net.Socket.connect(Socket.java:579) [rt.jar:1.7.0_75]
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:625) [jsse.jar:1.7.0_75]
	at org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:501) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:464) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:55) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.transport.AbstractInactivityMonitor.start(AbstractInactivityMonitor.java:138) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58) [activemq-client-5.11.1.jar:5.11.1]
	at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:340) [activemq-client-5.11.1.jar:5.11.1]
	... 10 more

12:22:23,726 ERROR [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-threads - 1) Endpoint will try to reconnect to the JMS broker in 30 seconds
12:22:23,727 ERROR [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-threads - 2) Endpoint will try to reconnect to the JMS broker in 30 seconds

Now start the activemq broker. After about 30 seconds, you should see something like this:

12:23:23,806 INFO  [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-threads - 1) Successfully established connection to broker [ssl://localhost:61617?jms.rmIdFromConnectionId=true]
12:23:23,813 INFO  [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-threads - 2) Successfully established connection to broker [ssl://localhost:61617?jms.rmIdFromConnectionId=true]

This means the connection between JBoss FSW and ActiveMQ is established. To prove this, we can issue the following commands:

Gary2013@Guojiangs-MacBook-Pro:~/jFSW/6.1/jboss-eap-6.1/standalone$ lsof -iTCP -P | egrep 61617 | egrep ESTAB
java      10669 Gary2013 1063u  IPv4 0x9b93e9761ab85c83      0t0  TCP localhost:55666->localhost:61617 (ESTABLISHED)
java      10669 Gary2013 1064u  IPv4 0x9b93e976184e1fc3      0t0  TCP localhost:55667->localhost:61617 (ESTABLISHED)
java      10777 Gary2013  149u  IPv6 0x9b93e976130931b3      0t0  TCP localhost:61617->localhost:55666 (ESTABLISHED)
java      10777 Gary2013  159u  IPv6 0x9b93e97613092cb3      0t0  TCP localhost:61617->localhost:55667 (ESTABLISHED)
Gary2013@Guojiangs-MacBook-Pro:~/jFSW/6.1/jboss-eap-6.1/standalone$ 

Now, we can check the JNDI name from the JBoss FSW console. Here is what I see:

References

Redhat References

No comments:

Post a Comment

Anypoint Studio Error: The project is missing Munit lIbrary to run tests

Anypoint Studio 7.9 has a bug. Even if we following the article: https://help.mulesoft.com/s/article/The-project-is-missing-MUnit-libraries-...