Show TOC

Procedure documentationHandling Exceptions Locate this document in the navigation structure

 

JMS Provider Exceptions

JMS Provider exceptions are those caused by the JMS infrastructure rather than the application. One common cause is a server crash. Applications can be notified for such error conditions through the JMS connection by registering an exception listener. You can provide your own implementation of the javax.jms.ExceptionListener interface, which defines a single method called onException(). Applications implement some failover logic in the onException() which re-creates the JMS resources used by them.

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.

Application Exceptions

Application exceptions are those thrown by the application code, for example a RuntimeException thrown in the onMessage() method of a message listener (for example, a message-driven bean). The JMS Provider attempts to deliver a message to a consumer until the message is acknowledged, which means that if an exception is thrown in the onMessage() method, the JMS Provider will redeliver this message. This could cause an endless loop processing a single message.

To prevent endless message redelivery, there is a configurable limitation for the maximum number of message delivery attempts. When the maximum number is exceeded, the message is considered undeliverable (dead message), and it is automatically moved to a dead message queue.

To configure the maximum number of message delivery attempts, you have to either:

  • Provide custom properties in the JMS resources descriptor, which are applied upon deployment

or

  • Use the SAP NetWeaver Administrator to modify the default setting after the resources have been created.

The default maximum number of delivery attempts is 5.

Procedure

Handling JMS Provider Exceptions

You implement the onException() method. If an exception occurs, execute custom logic to re-create your JMS resources.

Syntax Syntax

  1. /**
    
     * Handle asynchronous errors with the connection.
    
     */
    
    public void onException(javax.jms.JMSException jsme) {
    
       // Try to reconnect
    
    }
    
End of the code.

To register your exception listener, use:

Syntax Syntax

  1. // Register this class as the exception listener.
    
    connection.setExceptionListener(
    
       (javax.jms.ExceptionListener) ExceptionListenerImpl);
    
End of the code.
Handling Application Exceptions

To set the maximum delivery attempts property via deployment, consider the following sample jms-resources.xml descriptor:

Syntax Syntax

  1. <?xml version="1.0" encoding="UTF-8"?>
    
    <jms-resources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    
       xsi:noNamespaceSchemaLocation="jms-resources.xsd">
    
       <application-name>MyApplication</application-name>
    
       <destination>
    
          <name>MyQueue</name>
    
          <type>javax.jms.Queue</type>
    
          <sap-local-destination-type>
    
             <virtual-provider>default</virtual-provider>
    
             <property>
    
                <description>Maximum Delivery Attempts</description>
    
                <config-property-name>
    
                   maxDeliveryAttempts
    
                </config-property-name>
    
                <config-property-value>30</config-property-value>
    
             </property>
    
          </sap-local-destination-type>
    
       </destination>
    
    </jms-resources>
    
End of the code.