Tuesday, July 5, 2011

MQ Adapters with Opaque message type - Different ways to send a message.

MQ Adapters define two kinds of message payloads:

1. Opaque Schema
2. Schema file ( xsd) that contains a specified schema element.

Chosing opaque schema do not need to specify a message schema.By default the file/message is passed through in base-64 encoding.However

If the message is already base-64 encoded, the MQ Adapter will decode the message before placing in the Queue.


This is very useful certain times i) when the destination service who is listening/dequeuing to/from the MQ is expecting the message in the already decoded format.ii) (i) and when the destination is not confirmed to one message type and hence sender forced to use Opaque format.iii)when destination is listening to a message schema which has targetnamespace as null/empty.

For Case iii) situations , sender could have used the message xsd(destination is expecting) while sending instead of using an opaque schema , if the schema has a proper namespace(not null or empty) defined. As an empty target namespace xsd restricts the wizard of MQ adapter to define it , we are forced to use opaque schema.
Although it's not a right design for the destination app to have bad namespaces defined,we often end up in having this kind of services in the real scnarios.

So in these cases sender can encode the message to binary-64 before sending it to MQ so that the destination gets a decoded non binary64 message.

Given below is a sample code that encodes a message using a java embedding activity in BPEL process :

try
{

String input = (String)getVariableData("invServiceRequestStr");
String encoded;
com.collaxa.common.util.Base64Encoder Encoder = new com.collaxa.common.util.Base64Encoder();
encoded = Encoder.encode(input);
setVariableData("encodedMessageVar", encoded);
}
catch(Exception e)
{
e.printStackTrace();
}

Caveats:
1. If you are using 11g then you must use "oracle.soa.common.util.Base64Encoder" instead of com.collaxa.common.util.Base64Encoder.
In your .bpel you may need this :

FYI - This is present at - $JDEVHOME\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime.jar.

2. If your input to be converted is not plain string but element then use the below
String base64 = ((oracle.xml.parser.v2.XMLElement)getVariableData("MyElement")).getFirstChild().getNodeValue();

Summary :
Sender of the MQ message can encode the message which will be decoded by the MQ Adapater framework internally before placing into the queue ,if the schema used is a Opaque.

1 comment:

  1. Hi,

    This site is pretty good.I have gone through your post which is on ways to send a message.I found more information about the MQ adapters,while I was crawling the search engines.Thanks a lot.

    Oracle R12 Upgrade.

    ReplyDelete