-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn.js
executable file
·65 lines (54 loc) · 1.54 KB
/
conn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
// Import the MQ package
var mq = require('ibmmq');
var MQC = mq.MQC; // Want to refer to this export directly for simplicity
// The queue manager to be used.
var qMgr = "QM1";
var hConn;
function formatErr(err) {
return "MQ call failed in " + err.message;
}
// When we're done, close queues and connections
function cleanup(hConn) {
}
function sleep(ms) {
return new Promise(resolve=>{
setTimeout(resolve,ms);
});
}
// The program starts here.
// Connect to the queue manager.
console.log("Connection test started...");
// Create default MQCNO structure
var cno = new mq.MQCNO();
// And use the MQCD to programatically connect as a client
// First force the client mode
cno.Options |= MQC.MQCNO_CLIENT_BINDING;
// And then fill in relevant fields for the MQCD
var cd = new mq.MQCD();
cd.ConnectionName = "localhost(1414)";
cd.ChannelName = "DEV.APP.SVRCONN";
// Make the MQCNO refer to the MQCD
cno.ClientConn = cd;
// MQ V9.1.2 allows setting of the application name explicitly
if (MQC.MQCNO_CURRENT_VERSION >= 7) {
cno.ApplName = "Node.js 9.1.2 ApplName";
}
// Now we can try to connect
mq.Connx(qMgr, cno, function(err,conn) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQCONN to %s successful ", qMgr);
// Sleep for a few seconds - bad in a real program but good for this one
sleep(3 *1000).then(() => {
mq.Disc(conn, function(err) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQDISC successful");
}
});
});
}
});