Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

java - Stand-alone JMS application that is provider-independent

An application that runs inside a J2EE container can use JMS without knowing anything about the underlying JMS implementation (e.g., if it was using Solace, you could use MQ instead, by changing only configuration). But what about a stand-alone application, i.e., one that doesn't run in a J2EE container? How can it be made independent of JMS provider? If that's impossible, how close can you get?

question from:https://stackoverflow.com/questions/65853640/stand-alone-jms-application-that-is-provider-independent

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can get a 100% portable standalone JMS application with essentially no extra work on your part if the JMS providers you're switching between also provide a JNDI implementation. The JMS specification doesn't require JNDI but it establishes the convention that JNDI be used to locate administered objects like connections factories and destinations so it is very common for JMS providers to also provide a JNDI implementation as well.

In short your application can simply use the JMS and JNDI APIs. JMS and JNDI implementation details can be isolated to a jndi.properties file placed on the application's classpath. Switching between providers would be as simple as changing this properties file and changing the jars on the classpath.

If the JMS providers you're switching between don't provide JNDI implementations then you'll have to use implementation-specific code to create your connection factories and destinations. This will, of course, hurt portability, but you should be able to create your own API to isolate these details to classes which you can switch out for yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...