Wednesday, June 15, 2011

OSB with JMS Queues

I don't often get to play with Oracle Service Bus much anymore, but I always enjoy the chance when it comes along. Right now that need has indeed arrived in the form of JMS messaging.
OSB makes message management easy, queues or topics, messages to either can be enqueued or dequeued with simple services. Let me show you how.

Here is the use case
  1. Dequeue a message on a JMS queue
  2. Write message payload to a report
  3. Write out and queue new message on another queue, possibly after transformation for another service/system to collect, and,
  4. Make the write action call-able via a Web Service interface.
The only gotcha with OSB is this simple rule.

Business Services only Enqueue messages
Proxy Services only Dequeue messages

Understanding, remembering and applying this principal make's the whole thing easy.

I have created two WebLogic Server JMS queues which I will use in this example; andrewq1 and andrewq2.

Lets begin.
1. Login to the OSB console and create whatever folder structure you like.
2. Create a Business Service to write (enqueue) the message payload using the JMS transport adapter. Make sure you use the jms format; eg jms://192.168.13.136:8011/jms.andrewconnfactory/jms.andrewq2
I named mine writeQ.


3. Enable the Operational Settings for Monitoring and Tracing. Save and Submit.
4. Create a Proxy Service now to read (dequeue) the JMS messages.
5. Much the same as the Business Service configure the message payload to use the JMS transport adapter. Make sure you use the jms format; eg jms://192.168.13.136:8011/jms.andrewconnfactory/jms.andrewq1
I named mine readQ.




6. Enable the Operational Settings for Monitoring and Tracing. Save and Submit. 
7. Now we need to modify the Message Flow so the readQ Proxy Service knows what to do and writes out a message report so we can view the payload via the OSB operations dashboard.
8. Create a Pipeline pair and add a stage as shown.


9. Modify the stage actions to write out the dequeued payload to a report, and then route the payload to the queue andrewq2 using the writeQ business service. We could also handle some transformation etc here, but thats for another post :-)


10. That's it for OSB, Save and Submit your changes. Lets start testing!
11. We can cheat at the moment and use the WebLogic JMS message queue utility available from the Queue Monitoring Tab. We could also write a Business Service to write a message to this queue too, and we have created one already, but this way adds another option to this example.
12. Select show messages on the outbound queue from the monitoring tab.


13. Select the new button. You can also see the queued messages sitting here as well, not that there will be any as OSB is polling this queue for messages now and will act to dequeue as soon as one is written.


14. Create a new message and make sure you set the message type to be TextMessage.




15. That will create a message on the first queue, OSB will collect it, write out the payload to a report and write the message to the second queue. To view the report select Message Reports from the Operations Dashboard.




16. Selecting this message will show you the payload details and the transaction information.


17. When you select details you will see the xml payload.


18. Now we can go to the second queue (mine was called andrewq2) and you will see some messages queued awaiting collection.




19. And again you can select a message to see the contents. No surprise here, the payload shows what I typed in earlier.




And thats it. Well there is alot more that could and probably should be done, but this is just a taster, and you can extend what you have created now as you please.

Enjoy and don't forget to look in sometimes on WebCenter's very capable integration cousin - OSB.