In a recent engagement I was faced with the challenge of using Apache ActiveMQ for the first time. After learning a little bit about ActiveMQ, I had to connect to it from Oracle WebLogic Server for message consumption, so I decided on using a Foreign Server configuration.
Well, the first part of this is to add the libraries of ActiveMQ to WebLogic's classpath. I had to add the following libraries to my DOMAIN\lib directory (I'm using ActiveMQ 5.5.1):
activemq-core-5.5.1.jar
log4j-1.2.14.jar
slf4j-api-1.5.11.jar
slf4j-log4j12-1.5.11.jar
osgi.core-4.3.0.jar
The OSGI JAR does not come with Apache ActiveMQ and was downloaded directly from http://www.osgi.org. It's necessary due to the fact that ActiveMQ has some services based on OSGi APIs which are registered during startup.
After that, we need to configure the Foreign Server. For the Foreign Server, we specify the Initial Context Factory, URL for the ActiveMQ and some properties to configure how ActiveMQ will understand / emulate JNDI lookups performed by WebLogic Server.
Values that should be provided during the Foreign Server configuration:
- JNDI Initial Context Factory: org.apache.activemq.jndi.ActiveMQInitialContextFactory
- JNDI Connection URL: <ACTIVEMQ'S URL>
- JNDI Properties: <PROPERTIES TO CONFIGURE JNDI LOOKUPS>
As mentioned above, we should specify the JNDI Properties during configuration of the Foreign Server as it will guide how the JNDI lookups are made.
ActiveMQ provides the support for JNDI through the specification of properties specified during the Initial Context Factory creation. For example, to specify the name of the JMS Connection Factory you use a property called connectionFactoryNames and specify the names as a list of comma-separated values and the name of the queues and topics follow the convention queue/topic.JNDIName=PhysicalName. For more info, click here.
For example, if you have a queue named myQueue in ActiveMQ, and specify the following as the properties:
connectionFactoryNames=MyConnectionFactory
queue.myQueue=myQueue
A connection factory with JNDI name MyConnectionFactory and a queue jndi named myQueue will be available for lookup.
The following image shows the final configuration of the Foreign Server for our sample:
Now, we just map the remote destination (queue and/or topic) and connection factory names to local names, what allows us to create a level of abstraction. Each one of these settings are configured in the respective tab of the Foreign Server configuration.
Bellow, we see both images with the configuration of Destinations and Connection Factories.
In the configuration shown, we changed the local names of the queue and connection factory by adding a jms. in front of the JNDI name.
If we look at the server's JNDI tree, we see our both objects coming from ActiveMQ:
And clicking one of the links in the JNDI tree view, we see the objects are instances of ActiveMQ classes:
Well, that's it! Now, it's just a matter of looking the objects up from WebLogic itself and using them without caring if they are remote or not.