IBM Bluemix MQ Light

IBM MQ Light managed service provides the messaging features needed for building applications with decoupled components. Feature wise it is a scaled down version of the IBM Websphere MQ. It is built on the Advanced Messaging Queueing Protocol (AMQP).

Applications interact with MQ Light instance by getting the credentials & connection string from the VCAP_SERVICES environment variable. Once connected the publisher can publish messages to the dynamically created topics. The messages are held in the destination till either the subsriber reads them off the queue or the message expires or the destination expires. Here is a quick rundown of the various parts of this queuing system

    • Topic                     Created dynamically
    • Messages              Text, Name-Value pairs, Binary, Empty
    • Destination           Holds messages on behalf of the subscriber. 

Scaling

Destinations may be shared or exclusive. If the destination is shared by multiple subscribers the messages are distributed across multiple subscribers in a round robin fashion. In other words if there are two subscribers attached to a destination and two messages ("hello"   "world") are delivered to the destination then the first subscriber will receive "hello" and the second subscriber will receive "world". 

 

Message Time To Live (TTL)

 

Messages can be assigned an expiry value.  By default messages are held in the destination for 7 days. A maximum of 30 days can be assigned.

 

Destination Time To Live (TTL)

Destination TTL applies when no subscriber is actively connected to it. If the implementation is such that subscriber may go offline for longer periods of time then this should be adjusted appropriately otherwise message loss may occur. By default TTL=0 in other words the destination is destroyed as soon as the subscriber disconnects. A maximum of 30 days may be assigned to the destination TTL.

 

Delivery Assurance Models

MQ Light supports two delivery assurance model.

 

  1. At-Most-Once              
    If this is used Message loss is acceptable e.g., an internet chat application
     
  2. At-Least-Once              
    Message loss never occurs but app has to take care of duplicates e.g., credit card transactions

Security

Over the wire messages are secured via SSL. Messages get written to the file system so it is recommended that messages be encrypted.

 

Code

Lets have some fun with coding MQLight message publisher and subscriber on Bluemix. Following scenario is what we will code:

 

  • Bluemix web application receives message content from the browser and published the message
  • Bluemix no-route application (or background app) subscribes to the messages and write out received messages to logs

 

 

 

Code is available in GitHub.

github.com/acloudfan

 

Interested in Learning more?

Take my Bluemix Application development & certification course at UDEMY.