1
votes

I've got a Spring application which needs to look up a JMS destination in order to do it's work. Depending on whether we are in a development or system testing environment we will be using different JMS implementations. (Oracle AQ in system test with WebLogic, Apache ActiveMQ deployed in Jetty for Dev)

I have configured ActiveMQ and deployed it fine and it creates it's destinations in the activemq.xml file:

<destinations>
    <queue physicalName="handlersDest" />
    <topic physicalName="notificationsDest" />
</destinations>

When I start my handler (Spring) application it does a lookup for the destinations:

<jee:jndi-lookup id="handlersDest"  jndi-name="$handlersDest">
    <jee:environment>
        java.naming.factory.initial = ${jndi.jms.naming.factory.initial}
        java.naming.provider.url = ${jndi.jms.naming.url}
        queue.handlersDest = handlersDest
    </jee:environment>
</jee:jndi-lookup> 

My problem is that I have to add the following line to the environment for it to work:

queue.handlersDest = handlersDest

I know this is telling ActiveMQ's initial context that there is a destination called "handlersDest" and that it should ensure it is registered under the queue name "handlersDest" but I don't know why I need to do this in the client application?

Can't I predefine these JNDI names in the activemq.xml or somewhere else in my application which deployes activemq?

1

1 Answers

0
votes

The answer is no, active-MQs intial context does not support predifing the jndi names of destinations.

I solved the problem by making the jndi setup configurable as a property so that it could be set to blank when using another provider which didn't need further configuration of jndi.

For example:

<jee:jndi-lookup id="handlersDest"  jndi-name="$handlersDest">
    <jee:environment>
        java.naming.factory.initial = ${jndi.jms.naming.factory.initial}
        java.naming.provider.url = ${jndi.jms.naming.url}
        queue.handlersDest = handlersDest
    </jee:environment>
</jee:jndi-lookup> 

becomes:

<jee:jndi-lookup id="handlersDest"  jndi-name="$handlersDest">
    <jee:environment>
        java.naming.factory.initial = ${jndi.jms.naming.factory.initial}
        java.naming.provider.url = ${jndi.jms.naming.url}
        ${jndi.config}
    </jee:environment>
</jee:jndi-lookup> 

This way I can specify the jndi.config property to be "queue.handlersDest = handlersDest" when deployed with active-mq. But can leave the value blank when it is not needed.

The other answer is to not use active-mqs inital context but to use the initial context provided by the container which can be configured to contain the destinations from active-mq.