...
The steps are separated into different methods to make the implementation more readable as well as reusable.
Excerpt |
---|
createConnection(String url)
This method instantiates |
a ConnectionFactory
a ConnectionFactory object with an ActiveMQConnectionFactory object and creates |
a a Connection object through the factory |
method method createConnection() . The ActiveMQConnectionFactory object has to be instantiated with the URL of the MQ server. Code Block |
---|
language | java |
---|
title | createConnection(String url) |
---|
linenumbers | true |
---|
collapse | true |
---|
| 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;
} |
|
createSession(Connection connection)
The method is called with an already instantiated Connection
object and initiates a Session
object through the Connection
objects createSession(boolean transacted, int acknowledgeMode
)
method.
...