博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JNDI support differences between Tibco EMS and ActiveMQ
阅读量:5243 次
发布时间:2019-06-14

本文共 3334 字,大约阅读时间需要 11 分钟。

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               // ActiveMQ10 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               // Tibco18 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 context26 27               javax.naming.Context ctx = new javax.naming.InitialContext(props);28 29  30 31               // lookup an existing topic32 33               javax.jms.Topic myTopic = (javax.jms.Topic) ctx.lookup("MyTopic");34 35               System.out.println(myTopic);36 37              38 39 // lookup an existing queue40 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

你可能感兴趣的文章
guava API整理
查看>>
无锁编程笔记
查看>>
jquery mobile
查看>>
如何在vue单页应用中使用百度地图
查看>>
Springboot使用步骤
查看>>
Spring属性注入
查看>>
Springboot-配置文件
查看>>
Springboot-日志框架
查看>>
P1192-台阶问题
查看>>
一、使用pip安装Python包
查看>>
spring与quartz整合
查看>>
Kattis之旅——Eight Queens
查看>>
3.PHP 教程_PHP 语法
查看>>
Duilib扩展《01》— 双击、右键消息扩展
查看>>
利用Fiddler拦截接口请求并篡改数据
查看>>
python习题:unittest参数化-数据从文件或excel中读取
查看>>
在工程中要加入新的错误弹出方法
查看>>
PS 滤镜— — sparkle 效果
查看>>
snmpwalk命令常用方法总结
查看>>
网站产品设计
查看>>