Nov 142012
 

Hi,

I had the problem, that it should not be allowed to run 2 instances of the client simultaneously with the same broker.

I fixed that issue by setting the JMS Property ClientID.
When connecting to the broker, you can set a clientID. This ID is then registered on the Broker. If you now run that tool again (while the first instance is still running), then the second instance tries to connect, but the broker does not allow a second instance with the same clientID.

 connection.setClientID("Philipps_Tool");

Code Example:

// Create a JNDI API InitialContext object
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
props.setProperty(Context.PROVIDER_URL, server);

jndiContext = new InitialContext(props);
connectionFactory = (ConnectionFactory) jndiContext.lookup("ConnectionFactory");
requestQueue = (Destination) jndiContext.lookup("dynamicQueues/" + requestQueueName);
responseQueue = (Destination) jndiContext.lookup("dynamicQueues/"+ responseQueueName);

//Connect to  ActiveMQ
connection = connectionFactory.createConnection();
connection.setClientID("Philipps_Tool");   
// this helps to ensure, that not 2 instances can connect to the broker simultaneously
// because it is not allowed to connect to the same broker with the same clientID
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

Sorry, the comment form is closed at this time.