Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The steps are separated into different methods to make the implementation more readable as well as reusable.  Excerpt

createConnection(String url)

Excerpt

This method instantiates a ConnectionFactory object with an ActiveMQConnectionFactory object and creates a Connection object through the factory method createConnection().

The ActiveMQConnectionFactory object has to be instantiated with the URL of the MQ server.

Code Block
languagejava
titlecreateConnection(String url)
linenumberstrue
collapsetrue
public Connection createConnection(String uri){
    ConnectionFactory factory = new ActiveMQConnectionFactory(uri);
    Connection connection = null;
    try {
        connection = factory.createConnection();
    } catch (JMSException e) {
        LOGGER.error("JMSException occurred while trying to connect: " , e);
    }
    return connection;
}

...