I'm working with Java EE and ActiveMQ. I want to realize a JMS Queue where I can send messages to my QUEUE and a Consumer + MessageListener should read this messages.
The Code for my Consumer ist the following:
private void initializeActiveMq() throws JMSException {
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
// Create a Connection
connection = connectionFactory.createConnection();
connection.start();
// Create a Session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Queue)
Queue queue = session.createQueue(queueName);
// Create a MessageConsumer from the Session to the Queue
consumer = session.createConsumer(queue);
consumer.setMessageListener(this);
}
But the problem is, every time i will run this code it ads a new consumer to my queue, and then i have some strange behavior the consumers did then not deliver the messages correctly. If i have only one consumer it works perfect.
So how can I make sure that I have only one consumer in my queue?