MQ

MQ

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only

Try the MQ Light Node client….from your browser! 

Wed March 04, 2020 01:21 PM

LaurenceBonney
I noticed the folks at npmjs.org have added a link to Tonic giving you a browser based sandpit to run your MQ Light Node application in.

tonic_mqlight

Pair this up with the external connectively of the MQ Light Bluemix service and you have yourself an MQ Light development sandpit without ever having downloaded a thing to your local machine.

Having created an MQ Light Bluemix service and navigated to the service's Service Credentials page. Grab the 'connectionLookupURI' as your MQ Light service parameter and the username and passwords provided there also, pop them into your createClient() request within your MQ Light application and away you go!

As an example (below), throwing together a basic MQ Light application to subscribe to a 'news/technology' and then send a message to itself, we see the application start an MQ Light client, connect, subscribe, send and receive the message and end.

Basic code example:
  
var mqlight = require("mqlight")

var client = mqlight.createClient({service: '<your service connectionLookupURL here>', user: '<your service credentials username here>', password: '<your service credentials password here>'});

client.on('started', function() {
  client.subscribe('news/technology', function(err, pattern) {
    if (err) {
      console.error('Problem with subscribe request: ', err.message);
    } else {
        console.log('Subscribed to pattern: ', pattern);
        console.log('Sending message : Hello World!');
        client.send('news/technology', 'Hello World!');
    }
  });
    
  client.on('message', function(data, delivery) {
          console.log('Got message: ', data);
          console.log('Exiting.');
          process.exit(0);
  });
});


From adding the above code (putting in your particular service's credentials) and clicking "run" the console window below the code shows the expected console log lines:

Screenshot from 2015-12-02 19:58:36

You can then navigate through the output pages

Screenshot from 2015-12-02 19:59:04 Screenshot from 2015-12-02 19:59:22

The MQ Light UI within bluemix shows our client having connected in, and round-tripped our message.

Screenshot from 2015-12-02 19:55:11

And there you have it. Pretty neat!

Statistics
0 Favorited
5 Views
1 Files
0 Shares
1 Downloads
Attachment(s)
docx file
Try_the_MQ_Light_Node_client….from_your_browser!.docx   803 KB   1 version
Uploaded - Wed March 04, 2020
Global message icon