JNDI support differences between Tibco EMS and ActiveMQ - Perficient Blogs
Blog
  • Topics
  • Industries
  • Partners

Explore

Topics

Industries

Partners

JNDI support differences between Tibco EMS and ActiveMQ

Recently our team was working on Veracity Quick Start sprint, when I was trying to migrate the JMS provider implementation from Tibco EMS to ActiveMQ, I found that there are notable differences between these two JMS implementations on their JNDI support, which will be illustrated below.

1.  Code demonstration

The following codes show a main function which uses Java JNDI API to retrieve JMS queue and topic. We will try each implementation by putting relevant INITIAL_CONTEXT_FACTORY and PROVIDER_URL into the props object.

public class Main {

 

        public static void main(String[] args) throws Exception {

                        Properties props = new Properties();

                        // ActiveMQ

//                      props.put(Context.INITIAL_CONTEXT_FACTORY, “org.apache.activemq.jndi.ActiveMQInitialContextFactory”);

//                      props.put(Context.PROVIDER_URL, “tcp://localhost:61616”);

 

                        // Tibco

                        props.put(Context.INITIAL_CONTEXT_FACTORY, “com.tibco.tibjms.naming.TibjmsInitialContextFactory”);

                        props.put(Context.PROVIDER_URL, “tibjmsnaming://localhost:7222”);

 

                        // create a new intial context

                        javax.naming.Context ctx = new javax.naming.InitialContext(props);

 

                        // lookup an existing topic

                        javax.jms.Topic myTopic = (javax.jms.Topic) ctx.lookup(“MyTopic”);

                        System.out.println(myTopic);

                       

// lookup an existing queue

                        javax.jms.Queue myQueue = (javax.jms.Topic) ctx.lookup(“MyQueue”);

                        System.out.println(myQueue);

 

            }

 

}

2.  Try Tibco EMS

When using Tibco EMS, in order to let the codes run successfully, we need to retrieve myTopic and myQueue objects:

1) There must be a Tibco JMS server running on localhost: 7222.

2) A topic named MyTopic and a queue named MyQueue must already be defined.

No other configuration files needed.

3.  Try ActiveMQ

When you try ActiveMQ (uncomment line 5 and 6, and comment line 9 and 10), things are little different:

1) You don’t need to have MyTopic and MyQueue already exists on ActiveMQ server.

2) You even needn’t have a server running at localhost: 61616.

3) Put a jndi.properties file on your class path, in which you have already predefined the wanted queues and topics:

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory

java.naming.provider.url = tcp://0.0.0.0:61616

 

# register some queues in JNDI using the form

# queue.[jndiName] = [physicalName]

queue.MyQueue = example.MyQueue

 

# register some topics in JNDI using the form

# topic.[jndiName] = [physicalName]

topic.MyTopic = example.MyTopic

 

Or use a little different syntax when you invoke lookUp in your java codes: use dynamicTopics/MyTopic instead of MyTopic, and use dynamicQueues/MyQueue instead of MyQueue.

 

4.  Conclusion

I checked the documentation of these two products, also relevant sections in the book ActionMQ in action, and figured out the differences about their JNDI capability:

1) Tibco EMS implements a server-side JNDI provider, you actually need to communicate to server to get your defined queues and topics.

2) ActiveMQ implements a client-side JNDI provider, no communication with server is needed.

When you get queue or topic object by passing a name to lookUp(), it doesn’t mean they already exist on server, or they will be created at that moment. ActiveMQ queues and topics are dynamically created when you actually use them, for example, when you actually send a message to a queue.

Suffice to say, the JNDI support is completely local and has nothing to do with server.

One thought on “JNDI support differences between Tibco EMS and ActiveMQ

  1. EMS support dynamic creation of queues and topics , i tried this feature from business-works side , but you should enable this feature first in the server

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up

Categories