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.
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).
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With