Thursday, July 16, 2015

OSB 11g - Read JMS Custom Header Properties

JMS queue and Topics are mainly used for persistence and reliability, we use JMS adapter to connect to JMS queue or topic in SOA Suite but in OSB we use jms protocol to connect to JMS queue and topic, we can also use JCA adapter but 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 come across a requirement where 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.

In this post, we show how to read custom JMS header properties in OSB. For this post, we created one sample queue (TargetQueue) on local server and we put the message to this queue along with custom header property. We created one OSB project in eclipse under OSB configuration and created required folder structures.

In previous post, we see how we see set custom header property for JMS queue. Click here to read that post.

First create proxy service that will read the message from JMS queue, to create that right click on the proxy 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.

OSB_ReadCustomHeaderProperty_CreateProject

OSB_ReadCustomHeaderProperty_CreateProxy

OSB_ReadCustomHeaderProperty_serviceType




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 TargetQueue 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 as we need to read JMS header properties. If we don’t select this option then we not able to read the custom header property from JMS queue.
OSB_ReadCustomHeaderProperty_Transport


In the message flow tab of proxy service, add pipeline pair after start node. Add stage node in request pipeline and inside stage add log action. We added log action to log custom jms header property value.

OSB_ReadCustomHeaderProperty_MessageFlow


Click on log action and then click on expression. We read the JMS custom header property from inbound variable, you can read the custom header property value using below syntax.

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

Here MessageType is custom header property name.

OSB_ReadCustomHeaderProperty


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 writes custom header property value in log file.

OSB_ReadCustomHeaderProperty_Testing


Thursday, July 2, 2015

OSB 11g - Set JMS Custom Header Properties

JMS queue and Topics are mainly used for persistence and reliability, we use JMS adapter to connect to JMS queue or topic in SOA Suite but in OSB we use jms protocol to connect to JMS queue and topic, we can also use JCA adapter but 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 come across a requirement where we need to send extra parameters to system through JMS queue/topic but we don’t want to send that in message content so to achieve that we can use custom JMS header properties. We can set custom header property for JMS queue along with value and that can further read by target system and get required parameter value.

In this post, we show how to set custom JMS header properties in OSB. For this post, we created one sample queue (TargetQueue) on local server and we put the message to this queue along with custom header property. We created one OSB project in eclipse under OSB configuration and created required folder structures.

First create business service that will put the message to JMS queue, to create that right click on the business folder and click on new and choose business service option. Choose “Messaging service” as Service Type.

OSB Set JMS Custom Header Properties Create Business Service


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

OSB Set JMS Custom Header Properties Create Business Service


In Transport tab, choose jms from protocol drop-down as we are dealing with JNS queue i.e. we need to send that message to 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 TargetQueue JMS queue. Choose default settings for all other tabs and save the business service.

OSB Set JMS Custom Header Properties JMS Endpoint URI


Now let’s create proxy service, for that right click on newly created business service, click on Oracle Service Bus and then choose Generate Proxy service option. This will create the proxy service. Open the proxy service and open the message flow tab.

OSB Set JMS Custom Header Properties Create proxy Service


In the message flow tab of proxy service, you see route node is added as we created proxy service directly from business service. Since we need to set custom header property for JMS queue so we need to add Transport Header action in the request action of route node.

OSB Set JMS Custom Header Properties Proxy Message Flow


Open the Transport header action and in first tab (Transport Header) click on “Add Header” button, this will add one header in below window. To set custom header property for JMS, choose “Other” and mention custom header property name, for this use case we set “MessageType” as custom header property for JMS queue. Then choose “Set Header to:” and click on <Expression> and assign value to custom header property.

OSB Set JMS Custom Header Properties


Save your proxy service and deploy it to server. Now test the proxy service, to test it open OSB test console and send text message. Then go to JMS queue and open the message, you see custom header property showing in the JMS queue.

OSB Set JMS Custom Header Properties Testing


OSB Set JMS Custom Header Properties Testing