OSB's MQ Transport: how to set "legible" MessageId/CorrelationId

If you have to set a specific value to retrieve/correlate a MQ message, you must set the "correlationID" transport header like this:

CorrelationId Transport Header

But if you do this, when you browse the queue using MQ Explorer or other tool, you see a bunch of unreadable characters. If the consumer is waiting for "ID_123" as the value, the message will not be consumed, since the values doesn't match.

To correct this, you must pass a Base64 encoded ID to MQ Transport, not the plain ID. When processing the message, the transport will acknowledge the format and process the value accordingly. When the message reaches the MQ Server, the Correlation property will be displayed as expected. I didn't find a explanation to this, and there's no official documentation about it too. So, just do it :-)

Here's a code snippet to convert a String to Base64 using Sun's SDK:
import sun.misc.BASE64Encoder;

public class ConverterUtils {
	public static String convertStringToBase64(String value) {
		return new BASE64Encoder().encodeBuffer(value.getBytes());

	public static void main(String[] args) {
		if (1 <= args.length) {
			System.out.println(String.format("Original string: %s\nConverted: %s", args[0], ConverterUtils.convertStringToBase64(args[0])));

You can package this code, add the .jar as a resource to your project and then execute a Java Callout in order to convert the CorrelationID before setting the transport header. If you don't want or can't use Sun JDK, check out Apache Commons implementation (which demands a classpath change) or get an open source implementation like Harder's.

  MQ Transport documentation
  Converting String to Base64
  Apache Commons Codec
  Harder's Base64 implementation

Posted by Fabio Mazanatti at Jun 15, 2012 - 17:17
Tags: , ,

The author does not allow comments to this entry