Consuming messages from a JMS queue

A message in a queue can only be consumed by a single consumer. To consume a message on the OSB, a proxy service with the JMS Transport needs to be setup.

In this recipe, we will show how to implement a proxy service as a message consumer for the queue. The proxy service will act as a listener on the JMS queue and will get active as soon as a message can be consumed from the queue.

Consuming messages from a JMS queue

Getting ready

For this recipe, we need one queue from the OSB Cookbook standard environment and will then implement the proxy service to dequeue the messages from the queue.

How to do it...

Let's create the proxy service to consume messages from the SourceQueue. In Eclipse OEPE, perform the following steps:

  1. Create a new OSB project consuming-from-jms-queue and create a proxy folder within it.
  2. Create a new proxy service and name it JMSConsumer.
  3. Navigate to the General tab.
  4. Set the Service Type option to Messaging Service.
  5. Navigate to the Messaging tab
  6. Set the Request Message Type option to Text.
  7. Set the Response Message Type option to None.
  8. Navigate to the Transport tab.
  9. Select jms for the value of the Protocol drop-down listbox.
  10. Enter jms://localhost:7001/weblogic.jms.XAConnectionFactory/jms.SourceQueue into the EndpointURI field.
    How to do it...
  11. Navigate to the JMS Transport tab
  12. Set the Destination Type option to Queue.
    How to do it...
  13. Navigate to the Message Flow tab.
  14. Insert a Pipeline Pair node and add a Stage node to the Request Pipeline.
  15. Place a Log action into the stage.
    How to do it...
  16. Enter $body for the <Expression>, Content of$body in Request into the Annotation field and select Warning as the value of the Severity drop-down listbox.
  17. Save the project but do not yet deploy it to the OSB server.

    Now it's time to test the behavior of the OSB service. In WebLogic console, perform the following steps to put a message into the queue:

  18. Expand the Services node in the Domain Structure tree.
  19. Click on the Messaging node.
  20. Click on JMS Modules and in the list of modules click on OsbCookbookResources.
  21. Click on the queue SourceQueue.
  22. Click on the Monitoring tab.
  23. Enable the checkbox in front of OsbCookbookResources!SourceQueue and click Show Messages.
  24. Click on New to create a message.
  25. Enter This is a text message! into the Body field and click OK.
    How to do it...
  26. The message appears in the queue as shown in the following screenshot:
    How to do it...
  27. Click on the ID: <nnnnn.nnnnnnn> link to get the details of the message.

Now go back to Eclipse OEPE and deploy the project to the OSB server. The message should get consumed immediately and the OSB console output window should show the content of message (that is, the body variable).

Even though we have only sent a plain text string This is a text message!, on the OSB server the content is wrapped inside a <soapenv:Body> element. This is important to know if you require access to the value of the message.

How to do it...

In WebLogic console refresh the Summary of JMS Messages view for the SourceQueue and check whether the message has really been consumed.

How it works...

Setting the Service Type of a proxy service to Messaging Service allows us to set the Protocol to jms. On a proxy service, the JMS protocol always works inbound, that is, the proxy service is consuming messages from a queue. On a business service in contrast, the JMS protocol always works outbound, that is, the business service is putting the message to a queue.

The queue which should be used by the proxy service is specified by the Endpoint URI, together with the hostname and port of the JMS server and the connection factory to use.

After deploying the proxy service, it listens to the queue for messages and will consume it immediately and passes it to the message flow of the proxy service for execution.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset