1

I create a destination like this:

 Destination destination = session.createQueue("queue_name"); 

In this case if the queue named "queue_name" dont exist, it will be created.

I want to form a destination to a queue and in case it dont exist, i dont want to create it.

Is there a way to connent to a queue only if it exists?

3 Answers 3

1

I think you should be able to get a list of the available queues using DestinationSource from your connection. The you could look to see if the queue exists.

Havnt tried it, but think it looks like this:

 ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); ActiveMQConnection connection = (ActiveMQConnection)connectionFactory.createConnection(); DestinationSource ds = connection.getDestinationSource(); Set<ActiveMQQueue> queues = ds.getQueues(); 
Sign up to request clarification or add additional context in comments.

Comments

1

You have to use the security feature in ActiveMQ to limit the users who are allowed to create destinations. You can then configure a set of destinations in the ActiveMQ config which are always created. See this page on the subject and also this page on configuring security.

Comments

0

You can either do it through security configuration of your client (Consumer/Producer).

Or alternatively you can do it programmatically by getting the list of queues available and only connecting if it is in the list. ActiveMQ provides a class for this, but its not part of JMS (so you'll be restricted to an ActiveMQ specific implementation).

http://activemq.apache.org/maven/5.5.0/activemq-core/apidocs/org/apache/activemq/advisory/DestinationSource.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.