Thursday, September 24, 2015

In our previous post, we discussed about how to add and read custom header properties for JMS. In couple of scenario’s we need to use Message selector property for JMS. Let’s first understand what this property is and where this can be implemented.

In some cases our starting point is JMS queue/topic, where source system put the message to JMS queue/topic and OSB picks the message from that queue and process the message. Sometimes same queue/topics is used to process different messages e.g. source system put both “Sales Order” and “Shipment” messages to same JMS queue/topics but that messages should be picked by different OSB proxies as we have different logic for each message. This “Message Selector” property helps there, in Sales Order proxy service we mention that we pick only Sales Order message and in Shipment proxy we mention that we pick only shipment messages. Now let’s see how to implement this.

First create an OSB project and add required folder structure. Create proxy service that 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.


JMS Message Selector Create Project
JMS Message Selector Create Proxy



JMS Message Selector Proxy Message Type


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.

JMS Message Selector Proxy Transport


Go to next tab and open the advanced settings. Under that enter the value for “Message Selector”. E.g. in this case source system put the message to JMS queue with custom header property (“MessageType”), if this property value is “Valid” then only we need to pick   the message from JMS queue otherwise not.

JMS Message Selector Proxy property


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 request message.

JMS Message Selector Proxy Message Flow


Click on log action and then click on expression and put $body variable to log the request message.

Save your proxy service and deploy it to server. Now put message to JMS queue with custom header property “MessageType” equal to “Valid”. Proxy picks the message and do the check based on Message Selector property, since that is true so it process the message.

JMS Message Selector Success Testing


Now repeat the above test case but put the message to JMS queue with custom header property “MessageType” equal to “Invalid”. Proxy does the check based on Message Selector property, since that is false so it will not process the message and message will remain in queue itself.

JMS Message Selector ErrorTesting




0 comments :

Post a Comment