JNDI support differences between Tibco EMS and ActiveMQ

Introduction

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.

Code to demonstrate

Code below is a main function which use Java JNDI API to retrieve JMS queue and topic. We will try each implementation by put relevant INITIAL_CONTEXT_FACTORY and PROVIDER_URL into the props object.

 1 public class Main {
 2 
 3  
 4 
 5        public static void main(String[] args) throws Exception {
 6 
 7               Properties props = new Properties();
 8 
 9               // ActiveMQ
10 
11 //            props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
12 
13 //            props.put(Context.PROVIDER_URL, "tcp://localhost:61616");
14 
15  
16 
17               // Tibco
18 
19               props.put(Context.INITIAL_CONTEXT_FACTORY, "com.tibco.tibjms.naming.TibjmsInitialContextFactory");
20 
21               props.put(Context.PROVIDER_URL, "tibjmsnaming://localhost:7222");
22 
23  
24 
25               // create a new intial context
26 
27               javax.naming.Context ctx = new javax.naming.InitialContext(props);
28 
29  
30 
31               // lookup an existing topic
32 
33               javax.jms.Topic myTopic = (javax.jms.Topic) ctx.lookup("MyTopic");
34 
35               System.out.println(myTopic);
36 
37              
38 
39 // lookup an existing queue
40 
41               javax.jms.Queue myQueue = (javax.jms.Topic) ctx.lookup("MyQueue");
42 
43               System.out.println(myQueue);
44 
45        }
46 
47 }

Try Tibco EMS

When using Tibco EMS, in order to let the code run successfully, i.e. retrieved 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.

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 predefined the wanted queues and topics:

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

Conclusion

I checked the documentation of both products, also relevant sections in the book ActionMQ in action, and figure 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 a name passing to lookUp(), it doesn’t means they already exist on server, nor 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.

转载于:https://www.cnblogs.com/toowhite/p/3791201.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值