Creating connections

Beginning in version 6.0, EAServer provides a common connection type that you can use for both message queues and topics.

To create a connection to the EAServer JMS provider, a JMS client must have access to a ConnectionFactory object. See “Looking up a connection factory”.

Once you have created a connection, you must explicitly start it before EAServer can deliver messages on the connection. To avoid message delivery before a client has finished setting up, you may want to delay starting the connection. This code fragment uses a common connection factory to create a connection, then starts the connection:

Connection myConnect = myConnFactry.createConnection();

// other setup procedures

myConnect.start();

You can stop message delivery using the Connection.stop method, then use start to resume delivery. While a connection is stopped, receive calls do not return with a message, and messages are not delivered to message listeners. Any calls to receive or message listeners that are in progress when stop is called, complete before the stop method returns.

When you no longer need a connection, close it by calling Connection.close to release its resources and help your application run more efficiently.

With a single connection to EAServer, the message service can send and receive multiple messages. Therefore, a JMS client usually needs only one connection.

Setting the client ID

A connection for a durable topic subscriber must have a client ID associated with it so that EAServer can uniquely identify a client if it disconnects and later reconnects.

The default client ID is the client’s TCP/IP host name. To set the client ID to another value, you can either:

For more information about topic subscribers, see “Creating message consumers”.

ExceptionListener

To enable EAServer to asynchronously notify clients of serious connection problems, create and register an ExceptionListener. The javax.jms.ExceptionListener must implement this method:

void onException(JMSException exception);

To register a listener, call the Connection::setExceptionListener method, for example:

myConnect.setExceptionListener(MyExceptionListener);

If an exception occurs and a listener has been registered, EAServer calls the onException method and passes the JMSException, which describes the problem.