Friday, 1 July 2016

How to Read JMS Custom Header Properties


Via OSB we have two methods of invocation to JMS queue and topic (i) jms protocol (ii)JCA adapter. But in OSB jms protocol is always preferred.  We usually deals with XML or Non-XML content while working with JMS queue and topic and there are some pre-defined header properties for JMS queue and topic that are used for specific purpose.

Sometime we need to read extra parameters from JMS queue/topic, these extra parameters are custom JMS header properties. We can read custom header property for JMS queue in OSB.

Steps are to create proxy service that will read the message from JMS queue, to create that right click on the folder and click on new and choose proxy service option. Choose “Messaging service” as Service Type.

In Message Type configuration, select “Text” as Request Message Type as we will read simple text message to test this use case and choose “None” as Response Message Type as we are not sending any response back once we read the message from JMS queue.

In Transport tab, choose jms from protocol drop-down as we are dealing with JMS queue i.e. we need to read the message from JMS queue. In Endpoint URI text box fill the required values for JMS endpoint URI, for this use case we use default connection factory and name of JMS queue. Choose default settings for all other tabs and save the business service.

Make sure that “Get All Header” option is set to yes.  If we don’t select this option then we will not be able to read custom header property from JMS queue.

Now to read the JMS custom header property from inbound variable, We can use below syntax via assign activity.

var1 = $inbound/ctx:transport/ctx:request/tp:headers/tp:user-header[@name='QueueDetail']/@value

Here QueueDetail is custom header property name.

Save your proxy service and deploy it to server. Now put message to JMS queue along with custom header property. Proxy picks the message and fetch the custom header property in var1 variable. Which we can print via log activity on server.