Wednesday, January 22, 2014

Introduction to WebSphere MQ bridge for HTTP

The WebSphere® MQ bridge for HTTP is a Java™, Enterprise Environment (JEE) Web application. HTTP clients can send POSTGET, and DELETE requests to it to put, browse and delete messages from WebSphere MQ queues. The WebSphere MQ bridge for HTTP is not suitable for use with messages, if assured delivery is required.

Benefits

With the WebSphere MQ bridge for HTTP you can send and receive WebSphere MQ messages using HTTP from a wide variety of environments:
  • Environments that support HTTP, but not WebSphere MQ.
  • Environments that have insufficient storage space to install a WebSphere MQ client.
  • Environments that are too numerous to install the WebSphere MQ client on each system that requires access to WebSphere MQ.
  • Web-based applications from which you want to send or receive messages without coding your own bridge to WebSphere MQ.
  • Web-based applications that you want to enhance, using asynchronous techniques such as AJAX. WebSphere MQ bridge for HTTP makes WebSphere MQ queues and topics available using Representation State Transfer (REST) over HTTP.
HTTP support can be used with both point-to-point and publish/subscribe messaging topologies.

How does HTTP support work?

Figure 1. WebSphere MQ bridge for HTTP
The WebSphere MQ bridge for HTTP Web application receives HTTP requests from one or more clients. It interacts with WebSphere MQ on their behalf, and returns HTTP responses to them.
The WebSphere MQ bridge for HTTP is a JEE servlet that is connected to WebSphere MQ using a resource adapter. The HTTP servlet handles three different types of HTTP requests: POSTGET, and DELETE.
Table 1. WebSphere MQ bridge for HTTP verbs
HTTP RequestResult
POSTPuts a message on a queue or topic.
GETBrowses the first message on a queue. In line with the HTTP protocol, GET does not delete the message from the queue. Do not use GET with publish/subscribe messaging.
DELETEGets and deletes a message from a queue or topic.

HTTP POST example

HTTP POST puts a message to a queue, or a publication to a topic. The HTTPPOST Java sample is an example an HTTP POST request of a message to a queue. Instead of using Java, you could create an HTTPPOST request using a browser form, or an AJAX toolkit instead.
Figure 2 shows an HTTP request to put a message on a queue called myQueue. This request contains the HTTP header x-msg-correlId to set the correlation ID of the WebSphere MQ message.
Figure 2. Example of an HTTP POST request to a queue
POST /msg/queue/myQueue/ HTTP/1.1
Host: www.example.org
Content-Type: text/plain
x-msg-correlID: 1234567890
Content-Length: 50

Here's my message body that will appear on the queue.
Figure 3 shows the response sent back to the client. There is no response content.
Figure 3. Example of an HTTP POST response
HTTP/1.1 200 OK
Date: Wed, 2 Jan 2007 22:38:34 GMT
Server: Apache-Coyote/1.1 WMQ-HTTP/1.1 JEE-Bridge/1.1
Content-Length: 0

HTTP DELETE example

HTTP DELETE gets a message from a queue and deletes the message, or retrieves and deletes a publication. The HTTPDELETE Java sample is an example an HTTP DELETE request reading a message from a queue. Instead of using Java, you could create an HTTP DELETE request using a browser form, or an AJAX toolkit instead.
Figure 4 is an HTTP request to delete the next message on queue called myQueue. In response, the message body is returned to the client. In WebSphere MQ terms, HTTP DELETE is a destructive get.
The request contains the HTTP request header x-msg-wait, which instructs WebSphere MQ bridge for HTTP how long to wait for a message to arrive on the queue. The request also contains the x-msg-require-headers request header, which specifies that the client is to receive the message correlation ID in the response.
Figure 4. Example of an HTTP DELETE request
DELETE /msg/queue/myQueue/ HTTP/1.1
Host: www.example.org
x-msg-wait: 10
x-msg-require-headers: correlID
Figure 5, is the response returned to the client. The correlation ID is returned to the client, as requested in x-msg-require-headers of the request.
Figure 5. Example of an HTTP DELETE response
HTTP/1.1 200 OK
Date: Wed, 2 Jan 2007 22:38:34 GMT
Server: Apache-Coyote/1.1 WMQ-HTTP/1.1 JEE-Bridge/1.1
Content-Length: 50
Content-Type: text/plain; charset=utf-8
x-msg-correlId: 1234567890

Here's my message body that will appear on the queue.

HTTP GET example

HTTP GET gets a message from a queue. The message remains on the queue. In WebSphere MQ terms, HTTPGET is a browse request. You could create an HTTP DELETE request using a Java client, a browser form, or an AJAX toolkit.
Figure 6 is an HTTP request to browse the next message on queue called myQueue.
The request contains the HTTP request header x-msg-wait, which instructs WebSphere MQ bridge for HTTP how long to wait for a message to arrive on the queue. The request also contains the x-msg-require-headers request header, which specifies that the client is to receive the message correlation ID in the response.
Figure 6. Example of an HTTP GET request
GET /msg/queue/myQueue/ HTTP/1.1
Host: www.example.org
x-msg-wait: 10
x-msg-require-headers: correlID
Figure 7 is the response returned to the client. The correlation ID is returned to the client, as requested in x-msg-require-headers of the request.
Figure 7. Example of an HTTP GET response
HTTP/1.1 200 OK
Date: Wed, 2 Jan 2007 22:38:34 GMT
Server: Apache-Coyote/1.1 WMQ-HTTP/1.1 JEE-Bridge/1.1
Content-Length: 50
Content-Type: text/plain; charset=utf-8
x-msg-correlId: 1234567890

Here's my message body that will appear on the queue.

No comments: