node-red-contrib-ibm-mq
Version:
IBM MQ read/write nodes
58 lines (55 loc) • 2.23 kB
JavaScript
module.exports = function (RED) {
"use strict";
var EventBus = require('vertx3-eventbus-client');
function IBMMQWriteNode(config) {
RED.nodes.createNode(this, config);
var node = this;
this.url = config.url || 'http://localhost:8080/eventbus/';
this.eb = new EventBus(this.url);
this.host = config.host;
this.port = config.port;
this.channel = config.channel;
this.user = config.user;
this.pass = config.pass;
this.qmname = config.qmname;
this.qname = config.qname;
this.eb.onopen = function () {
node.on('input', function (msg) {
node.eb.send('vertx.' + node.id, msg, function (ar_err, ar) {
if (ar_err == null) {
node.send(msg);//For further processing on successful messages
} else {
node.error({
payload: "Received write reply: " + JSON.stringify(ar_err),
Type: node.type,
ID: node.id
});
}
});
});
config.cmd = "deploy";
node.eb.send("vertx.cmd", JSON.stringify(config), function (ar_err, ar) {
if (ar_err == null) {
node.status({fill: "green", shape: "dot", text: "connected"});
} else {
node.status({fill: "red", shape: "dot", text: "error!"});
node.error({
payload: "Received deploy reply: " + JSON.stringify(ar_err),
Type: node.type,
ID: node.id
});
}
});
};
this.on('close', function () {
config.cmd = "undeploy";
node.eb.send("vertx.cmd", JSON.stringify(config));
node.eb.close();
node.eb = null;
});
this.eb.onclose = function () {
//console.log('close................');
};
}
RED.nodes.registerType("ibm-mq-write", IBMMQWriteNode);
};