Show TOC Start of Content Area

This graphic is explained in the accompanying text Closing Connections and Handling Exceptions  Locate the document in its SAP Library structure

Use

You close the JMS connection when you are finished using it and the objects used must be released. You can choose either to manually close the sessions associated with the connection and then the connection itself, or to close the connection object only. In the last case, the JMS Provider automatically closes all associated sessions.

 This graphic is explained in the accompanying text

We recommend that you unsubscribe the durable subscribers when you no longer need them. The JMS Provider keeps all the messages that durable subscribers have not yet consumed, so unneeded ones can waste a significant amount of resources and degrade JMS Provider performance.

You can handle the connection exceptions using your own implementation of the class javax.jms.ExceptionListener.

This graphic is explained in the accompanying text

When you implement the onException() method, do not close the client connections that were used up to that moment in the method’s implementation. The JMS Provider does this for you. The client has to recreate the JMS resources of the application.

Procedure

Closing connections

If you are using a point-to-point connection, use the following code to close the connection object:

This graphic is explained in the accompanying text

// Close the queue connection

queueConnection.close();

If you are using a publish-subscribe connection, close the connection in the same way:

This graphic is explained in the accompanying text

// Close the topic connection

topicConnection.close();

Handling exceptions

You have to implement the onException() method of the ExceptionListener, and in case an exception occurs this will allow you to execute custom logic to avoid data loss.

For example:

This graphic is explained in the accompanying text

   /**

    * Handle asynchronous errors with the connection.

    */

   public void onException(javax.jms.JMSException jsme) {

      // Tries to reconnect

   }

To register the implementation use:

This graphic is explained in the accompanying text

// Register this class as the exception listener.

connection.setExceptionListener(

   (javax.jms.ExceptionListener) ExceptionListenerImpl);

 

End of Content Area