Skip to main content

Generic message retry and requeue with WebSphere Message Broker V6

Stephen Cox (stephencox@uk.ibm.com), Software Engineer, Software Lab Services, IBM
Stephen Cox is a Software Engineer on the Software Lab Services team at the IBM Hursley Software Lab in the UK. His expertise includes WebSphere MQ and WebSphere Message Broker. He is an IBM Advisory Accredited Professional, certified in Systems Administration of both WebSphere MQ and WebSphere Message Broker, and he received a Bachelors degree with Honours in Computer Systems Engineering from the University of Kent in the UK. You can contact Stephen at stephencox@uk.ibm.com.

Summary:  This article shows you how to use new function in WebSphere Message Broker V6 to implement delayed message reprocessing, which is a requirement in many WebSphere Message Broker implementations.

Date:  25 Jan 2006
Level:  Intermediate
Activity:  549 views

Introduction

Many customers using IBM® WebSphere® Message Broker solutions -- from single message-flow implementations to migration projects and beyond -- have the requirement to retry messages a defined number of times after a specified time interval. The delay may be needed because of a business process or the availability of a back-end system or database. This article shows you how to implement this requirement, including a configurable bar file that can be deployed without further development to provide the message retry and re-queuing functionality. This implementation uses new function in WebSphere Message Broker V6, including timeout processing and user-defined properties. The bar file and a sample message flow implementation are available for download below.

Software requirements

  • WebSphere Message Broker V6 or later
  • WebSphere MQ V5.3 or later

Implementing the message flow

This article shows you how to use WebSphere Message Broker to set up a simple message flow that provides delayed message re-queuing without requiring changes to other flows in a solution. A standard, mandatory MQ message header is used so that any message input to the re-queue flow should be identical on output, which allows the standard processing of main flows to process re-queued messages without any change in function. Here is a description of the process used by the flow -- for each step, the relevant node in the flow is indicated in Figure 1:

  • Read a message from an input queue (INPUT)
  • Check to see how many times the message has been retried (SET PARAMETERS)
    • If the retry count exceeds the maximum number of retries, then output to a maximum retry queue (MAXIMUMRETRY)
    • If the retry count is less than the maximum number of retries, then:
      • Delay the message for the delay period defined (TimeoutControl).
      • Remove any changes made on entry to this flow to ensure the output message is identical to input (Restructure Message)
      • Output the message to a queue to allow retry processing replyToQ or destinationQueue depending on the settings defined) (OUTPUT)


Figure 1. Flow implementation
Figure 1. Flow implementation

The flow uses the MQ Message Descriptor (MQMD) feedback field to record the number of retries used. The pre-defined application values of the feedback field are used to avoid conflict with system values. Other than the feedback field, the input message remains identical on output.

Important: If your application uses the feedback field of the MQMD, then this flow should not be used.

An assumption is made in the logic of the flow that the field OutputRoot.MQRFH2.usr.TimeoutRequest is not used in the incoming message. This field stores data needed for routing internally, and is deleted before outputting a processed message. If this is unacceptable, then the code can be changed to use a different field in the header. Although the MQ Rules And Format Header (MQRFH2) may be added during processing of the flow, any additions will be removed before output.

For this flow to operate correctly, any applications feeding this flow must ensure that they copy the MQMD feedback information from input to output, to ensure that the retry count can be maintained. If this does not happen, then retry state cannot be maintained and poisoned messages may result if successful processing is never achieved in the main flow.

Using the message flow

To use the implemented flow, several properties must be customised on the bar file prior to deployment. Once these properties have been set, no further changes are necessary for the flow to function:

  1. Import the bar file contained with this package into WebSphere Message Broker Toolkit.
  2. Change the configurable properties on the bar file to define settings specific to your installation.
  3. Deploy the bar file.

Usage scenario

A message flow exists that requires retry processing. For the input queues to this flow, you can define a backout threshold (BOTHRESH) and a backout queue (BOQNAME) in WebSphere MQ. This main flow will then attempt to process any incoming message the number of times defined by the backout threshold. If processing fails after reaching this threshold, the failure path of the input node will be executed. You can output messages that act as input to the re-queue flow either during processing of the failure path or by not ending processing during execution of the failure path (for example, by throwing an exception at the end of the failure processing). Therefore, you can set configuration options accordingly:

  • Input of the re-queue flow is set to:
    • The backout queue of main flow, or
    • A queue output from the failure terminal
  • Output of the re-queue flow is set to the input of the main flow.
  • Any messages arriving on the maximum message retry output queue will require manual intervention.

Configurable properties

Below is a list of the configurable properties that are relevant for the bar file prior to deployment. After setting these values and deploying the resultant bar file, WebSphere Message Broker will process any messages arriving at the entry to the re-queue flow:

delay*
Time in seconds to delay each message
destinationQueue
Destination queue for successfully delayed messages
destinationQueueManager
Destination Queue Manager for successfully delayed messages
failureQueue*
Destination queue for messages that could not be successfully delivered
failureQueueManager
Destination Queue Manager for messages that could not be successfully delivered
inputQueue*
Input queue to the retry flow
maxRetriesQueue*
Destination queue for messages that have exceeded the maximum retry count
maxRetriesQueueManager
Destination Queue Manager for messages that have exceeded the maximum retry count
retryCount*
The number of times to re-queue a message
Unique Identifier*
A unique identifier defined to the retry flow
useReplyToQ
Use values defined in the replyToQ and replyToQMgr fields of the MQMD as an alternative to the destinationQueue and destinationQueueManager

* These fields are required for the flow to function correctly.



Figure 2. Demonstration of configurable properties
Figure 2. Demonstration of configurable properties

Usage notes

  • To use more than one copy (not instance) of this flow in a broker, you must set a different flow name and Unique Identifier for each deployment of the bar file. If you deploy the same bar file to different execution groups, then only the Unique Identifier must be set.
  • The maximum retryCount is 999934463. (MQ defines the properties MQFB_APPL_LAST and MQFB_APPL_FIRST. The difference between these numbers is the flow's maximum retry count). The feedback field can be defined to any message containing an MQMD and does not affect the structure of messages output.
  • To retry indefinitely, use the value -1. Use with care, because it can cause an infinite loop resulting in a poison message.
  • If message contents are defined in the MQRFH2 header of an incoming message, then the corresponding message sets must be deployed in the same execution group as this flow. If this is not the case, then messages are delivered to the backout queue/dead letter queue defined for the input queue of the retry flow.
  • Transaction mode in the implemented flows is set to Yes. Therefore, when a broker starts, if there are any outstanding messages, they will all be output at the same time on restart. This ensures that no messages are lost.
  • The WebSphere MQ system queue SYSTEM.BROKER.TIMEOUT.QUEUE (defined when a message broker is created) is used to store the messages currently delayed. Make sure that the maximum defined queue depth for this queue is sufficient to store messages, and monitor it to ensure that the maximum depth is not exceeded.

Conclusion

This article has shown you how to implement re-queuing using using new function in WebSphere Message Broker V6, including timeout processing and user-defined properties. By modifying the code provided, you can extend the current implementation to apply to additional business logic.



Download

DescriptionNameSizeDownload method
Code samples in zip formatMessageRequeue.zip95 KBFTP|HTTP

Information about download methods


Resources

About the author

Stephen Cox is a Software Engineer on the Software Lab Services team at the IBM Hursley Software Lab in the UK. His expertise includes WebSphere MQ and WebSphere Message Broker. He is an IBM Advisory Accredited Professional, certified in Systems Administration of both WebSphere MQ and WebSphere Message Broker, and he received a Bachelors degree with Honours in Computer Systems Engineering from the University of Kent in the UK. You can contact Stephen at stephencox@uk.ibm.com.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere, Architecture
ArticleID=102477
ArticleTitle=Generic message retry and requeue with WebSphere Message Broker V6
publish-date=01252006
author1-email=stephencox@uk.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers