I am trying to build a basic Producer Consumer application. I have three queues for message processing and can have multiple producers and consumers. The basic problem that I am facing here is that when should I call the
connection.start()
method of the javax.jms.QueueConnection that I am using. All the examples listed online ( eg :- https://github.com/hornetq/hornetq/blob/master/examples/jms/jmx/src/main/java/org/hornetq/jms/example/JMXExample.java)
show that after we have produced a message on a destination and after we have started a consumer should we start the connection. i.e. The connection.start()
is usually the last thing to do. Is it possible that I could start my connection as and when it is created ? For example, something like this
Properties jndiProps = new Properties();
jndiProps.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
jndiProps.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
jndiProps.put("java.naming.provider.url", "localhost:1099");
context = new InitialContext(jndiProps);
QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup("/ConnectionFactory");
connection = factory.createQueueConnection();
connection.start();