Reputation: 5850
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?
Upvotes: 1
Views: 2129
Reputation: 22188
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).
Upvotes: 0
Reputation: 11557
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();
Upvotes: 1
Reputation: 18431
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.
Upvotes: 1