dlite922
dlite922

Reputation: 1994

JMS Connect to a Queue without any specific library

I want to create a class that sends a message to a messaging queue using AMQP protocol such as ActiveMQ or RabbitMQ, but without including any specific jar/file/library to those MQ providers.

Every example I see on the web uses one of the above technologies. I thought I was able to connect to a queue strictly using JMS? How can I de-couple my messaging technology with my Producer/Consumer classes so that I could switch out ActiveMQ with RabbitMQ without recompiling the code? Is this even possible?

/frustrated @ 7:00 PM :(

Thanks!

Upvotes: 1

Views: 768

Answers (3)

Nicholas
Nicholas

Reputation: 16056

Take a look at this: Implementing vendor-independent JMS solutions. Disclosure: I wrote it, a while ago, but I think you will find it addresses your question from the JMS perspective.

Update: As IBM's removed the page, here's a saved snapshot from archive.org Implementing vendor-independent JMS solutions

Upvotes: 2

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136012

You can try SwiftMQ AMQP 1.0 Java Client http://www.swiftmq.com/products/router/swiftlets/sys_amqp/client/index.html

Upvotes: 0

BevynQ
BevynQ

Reputation: 8269

Yes it is possible. What you want to do is make sure you do not refer to any ActiveMQ object in your code.

Then you need to create factory methods to acquire the ActiveMQ/RabbitMQ methods.

something like

public ConnectionFactory getConnectionFactory() throws IllegalAccessException, InstantiationException {
    Class<?> klass = Class.forName(System.getProperty("JMSConnectionFactory");
    return (ConnectionFactory)klass.newInstance();
}

Sadly The difficulty you will have is that each provider has slightly different initialisation code. So you need to support each one.

You can do it all by reflection but helper classes may be better.

Upvotes: 3

Related Questions