Enabling JMS message persistence

When we send messages to a JMS queue, the Message Delivery Mode option controls if a message is guaranteed to be delivered once, and if it is safely stored in the persistent store of the JMS server. There is also a non persistent option, where the messages are stored in memory and may be lost in case of a WebLogic or JMS server failure, or when the WebLogic server is rebooted.

In this recipe, we will set the delivery mode option on a JMS message with the OSB Transport Header action.

Getting ready

For this recipe, we will use a simple OSB project with one proxy and one business service:

Getting ready

You can import the OSB project into Eclipse from chapter-10getting-readyenabling-jms-message-persistence.

How to do it...

In OPEP, perform the following steps:

  1. Navigate to the proxy service Request.
  2. Navigate to the Message Flow tab.
  3. Drag a Transport Header action and drop it on the Request action lane of the Route action.
  4. On the Properties tab of the Transport Header select Outbound Request as the value for the Direction field.
  5. Click on Add Header.
  6. Select jms and then JMSDeliveryMode from the Defined drop-down list.
  7. Type 2 into the Set Header to field (1 = non-persistent and 2 = persistent).
    How to do it...
  8. Publish the project to the OSB server.

    By adding the Transport Header action into the message flow we are able to define the delivery mode of the JMS queue. By setting the JMSDeliveryMode to 2 we are defining that the messages should be persistent.

    We can easily check the result by invoking the proxy service with a test message and then browsing the message through the WebLogic console.

    To invoke the proxy service, perform the following steps through the service bus console:

  9. In the Project Explorer navigate to the proxy folder inside the enabling-jms-message-persistence project.
  10. Click on the Launch Test Console icon of the Request proxy service.
  11. Enter <message>OSB Cookbook</message> into the Payload field and click on Execute.

    To browse for the message inside the DestinationQueue, perform the following steps through the WebLogic console:

  12. Select Services | Messaging.
  13. Click on JMS Modules and in the list of modules, click on OsbCookbookResources.
  14. Click on the DestinationQueue queue.
  15. Navigate to the Monitoring tab.
  16. Enable the checkbox in front of OsbCookbookResources!DestinationQueue and click on Show Messages.
  17. Click on the ID link of the message and the JMS Message Detail window will be shown:
    How to do it...

How it works...

With a Transport Header action, we can set the transport-specific (header) properties on the business service. In case of a JMS business service, you can use the predefined JMS header properties. These JMS properties will be used when the business service sends a message to the queue.

There's more...

We can also override the delivery mode in WebLogic, which takes precedence over all the settings that the producer of the message specifies in the delivery mode.

In WebLogic Console, perform the following steps to override the delivery mode:

  1. Navigate to the Configuration tab of your queue.
  2. Click on the Overrides tab and set the Delivery Mode Override to Persistent:
    There's more...

    Even if the producer of the message specifies the non-persistent delivery mode, the message will be made persistent due to the override.

    If we don't override the delivery mode in WebLogic, we can define it on the JMS Transport tab of the business service. Just enable the Enable Message Persistence checkbox:

    There's more...

    The Enable Message Persistence property on the business service will not override what we have set in a Transport Header action.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset