Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic JMS Client

Tags:

java

jms

Does anyone know if it is feasible to write a Generic JMS client - ie. one that works with JMS from different providers (eg. Sonic, IBM SIB, Jboss etc)?

Every time I've written JMS client code it is always very implementation specific with dependent JARs and Context classes.

Thanks.

like image 562
Damo Avatar asked Mar 21 '10 23:03

Damo


4 Answers

Well, one best practice (at least for me) is to use the non-arg InitialContext constructor and to put provider specific stuff (like the initial context factory and the provider url) in a jndi.properties file on the class path instead of hard coding these things. You'll also need to put the "right" JMS provider JARs on the class path. In other words, you can have generic code but you still need to configure the runtime environment (unless you run your client code in a container like Spring).

like image 167
Pascal Thivent Avatar answered Oct 09 '22 15:10

Pascal Thivent


2 good answers already, but I'd like to add a bit of an explanation. JMS is an API standard, it does not define the wire protocol to the server. Therefore all JMS implementations have different wire protocols - therefore you'll always need the vendor-specific JARs. It is impossible to create a JMS client library that is compatible with all JMS providers.
In your source code you should avoid vendor-specific features (e.g. TIBCO EMS lets you access destinations with non-JNDI, native names and it has custom acknowledge modes). If you always use JNDI lookups, then only the JNDI URL and the initial context factory name will be specific to the server type.

like image 27
Miklos Csuka Avatar answered Oct 09 '22 13:10

Miklos Csuka


This is what Spring is for. You will have vendor specific implementation but the code should be the same. See 19.6 JMS and 21. JMS (Java Message Service) of the Spring 3.0 Reference.

like image 31
cletus Avatar answered Oct 09 '22 14:10

cletus


For anyone looking for a generic client in the future, try out HermesJMS that comes with plugins for the major JMS providers (ActiveMQ, WebSphere MQ, etc)

like image 29
Damo Avatar answered Oct 09 '22 13:10

Damo