0
votes

I am trying to add ActiveMQ as a JMS Provider in Websphere Application Server.

I have followed the instructions described here ActiveMQ 5.11 with WebSphere Application Server 8.5 and adapted to the topic.

Unfortunately I am not sure what I need to add in External JNDI name for both Topic Connection Factory and Topic definitions.

As per IBM documentation:

"External JNDI Name The JNDI name that is used to bind the queue into the application server name space.

As a convention, use the fully qualified JNDI name; for example, in the form jms/Name, where Name is the logical name of the resource.

This name is used to link the platform binding information. The binding associates the resources defined by the deployment descriptor of the module to the actual (physical) resources bound into JNDI by the platform."

From my understanding this should be the name that I am using in my app to access the resource defined in WAS.

I also have added the resources in my deployment descriptor as resources.

Any help would be highly appreciated.

Regards

1

1 Answers

1
votes

Given that you are accessing the resources via resource references (defined in your deployment descriptor), the configured JNDI name should match the lookup name that is defined in your resource reference.

For example, if your resource reference looks like this,

  <resource-ref>
    <res-ref-name>java:comp/env/jms/topicConnectionFactoryRef</res-ref-name>
    <res-type>javax.jms.TopicConnectionFactory</res-type>
    <lookup-name>jms/myTopicConnectionFactory</lookup-name>
  </resource-ref>

or if your resource-ref lacks lookup-name and you instead have a ibm-web-bnd.xml file with a binding-name,

  <resource-ref name="java:comp/env/jms/topicConnectionFactoryRef"
                binding-name="jms/myTopicConnectionFactory">
  </resource-ref>

then specify jms/myTopicConnectionFactory as the JNDI name. Application code will then be able to do:

TopicConnectionFactory tcf = InitialContext.doLookup("java:comp/env/jms/topicConnectionFactoryRef");

Application code could also perform a direct lookup of the JNDI name as follows (although using the resource reference is preferred because it is more spec compliant and standard across app servers),

TopicConnectionFactory tcf = InitialContext.doLookup("jms/myTopicConnectionFactory");

The same applies to javax.jms.Topic. If your resource environment reference in your deployment descriptor looks like this,

  <resource-env-ref>
    <resource-env-ref-name>java:comp/env/jms/topicRef</resource-env-ref-name>
    <resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
    <lookup-name>jms/myTopic</lookup-name>
  </resource-env-ref>

or if your resource-ref lacks lookup-name and you instead have a ibm-web-bnd.xml file with a binding-name,

  <resource-ref name="java:comp/env/jms/topicRef" binding-name="jms/myTopic">
  </resource-ref>

then specify jms/myTopic as the JNDI name of the Topic. Application code will then be able to do:

Topic topic = InitialContext.doLookup("java:comp/env/jms/topicRef");

Some optimizations/special cases: If you have neither lookup-name nor binding-name, then WebSphere Application Server computes a default binding via the resource reference name. If this is the case for your resource reference, then you will have a deployment descriptor such as the following without any bindings file,

  <resource-ref>
    <res-ref-name>jms/myTopicConnectionFactory</res-ref-name>
    <res-type>javax.jms.TopicConnectionFactory</res-type>
  </resource-ref>

In the above case, specify jms/myTopicConnectionFactory as the JNDI name. The application will be able to look it up as,

TopicConnectionFactory tcf = InitialContext.doLookup("java:comp/env/jms/myTopicConnectionFactory");