Instant messaging on IBM i
In a previous post we introduced Signal Messenger Integration module allowing you to easily send messages from an interactive 5250 terminal session. Today, we bring a short introduction how to do it from IBM i programs with the help of MSGQ or DATAQ objects. It is easier than you think.
The Green Screens IMS generic framework we made is materialized in the form of Signal Messenger Integration module (SMI later in text). The latest SMI release is extended to support exchanging messages between IBM i programs and Signal Messenger through DATAQ and MSGQ.
To learn how to do that, continue reading this short tutorial.
As SMI can work in both directions, to receive and send messages we need a pair of MSGQ or DATAQ objects. It is not mandatory to have both. If only output from IBM i programs are required, it is enough to use only one MSGQ or DATAQ object. It is solely on the developer to decide. In the example below, we use MSGQ pair as we want to send and receive messages into IBM i programs. DATAQ will do also.
The major difference between MSGQ and DATAQ is that DATAQ can have multiple readers and works in FIFO mode. Which one to use is at the developer to decide.
Tutorial
Before start, one have to create two MSGQ objects. One for sending, and one for receiving messages. So, let's create that first.
For receiving messages from SMI
CRTMSGQ MSGQ(QGPL/SMIIN)
For sending message to SMI
CRTMSGQ MSGQ(QGPL/SMIOUT)
Once created, MSGQ object must be registered to the SMI module through REST API. When registered, objects are auto saved and reactivated upon server restart. To prevent configuration persistence, set "persistence" to false.
The easiest way to do this from IBM i is by calling cURL
Register SMI message listener - to receive messages in MSGQ
curl --location --request POST 'http://localhost/service.signal/rest/v1/batch/receiver/queue/message'
--header 'key: 2dc75d88-38be-4449-8543-f3487312e10b'
--header 'Content-Type: application/json'
--data-raw '{
"user": "QSECOFR",
"password" : "QSECOFR",
"account" : "+385915551234",
"target" : "+385915551234",
"library" : "QGPL",
"object" : "SMIIN",
"persistent" : false
}'
Register MSGQ message listener - to send messages to Signal
curl --location --request POST 'http://localhost/service.signal/rest/v1/batch/sender/queue/message'
--header 'key: 2dc75d88-38be-4449-8543-f3487312e10b'
--header 'Content-Type: application/json'
--data-raw '{
"user": "QSECOFR",
"password" : "QSECOFR",
"account" : "+385915551234",
"target" : "+385915551234",
"library" : "QGPL",
"object" : "SMIOUT",
"persistent" : false
}'
The same can be done from NodeJS or even Web Browser JavaScript...
Prepare request first
let myHeaders = new Headers();
myHeaders.append("key", "2dc75d88-38be-4449-8543-f3487312e10b");
myHeaders.append("Content-Type", "application/json");
Register SMI message listener - to receive messages in MSGQ
let raw = JSON.stringify({"user":"QSECOFR","password":"QSECOFR",
"account":"+385915551234","target":"+385915551234",
"library":"QGPL","object":"SMIIN"});
let requestOptions = {method: 'POST',headers: myHeaders,body: raw,redirect: 'follow'};
fetch("http://localhost/service.signal/rest/v1/batch/receiver/queue/message", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Register MSGQ message listener - to send messages to Signal
let raw = JSON.stringify({"user":"QSECOFR","password":"QSECOFR",
"account":"+385915551234","target":"+385915551234",
"library":"QGPL","object":"SMIOUT"});
let requestOptions = {method: 'POST',headers: myHeaders,body: raw,redirect: 'follow'};
fetch("http://localhost/service.signal/rest/v1/batch/sender/queue/message", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
NOTE: MSGQ or DATAQ might be linked to specific Signal groups or mobile phone numbers available inside signal but not mandatory. If the target is not set, all received messages will be sent to MSGQ/DATA and all sent messages must have a phone number header to send messages to specific receivers.
We are almost there. What remains is a small CL code to receive messages from MSGQ or to send messages to MSGQ. This easy part we will leave for you to discover and play with. Hint is here https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rbam6/rmclp.htm
For a quick test, one can use SNDMSG and WRKMSG commands from a 5250 console.
To send message to SMI (linked to mobile phone or group):
SNDMSG MSG('Hello World!') TOMSGQ(QGPL/SMIOUT)
To send message to SMI (unlinked):
SNDMSG MSG('+385915551234:Hello World!') TOMSGQ(QGPL/SMIOUT)
To view received messages
WRKMSG MSGQ(QGPL/SMIIN)
Final word
We hope you dear reader found this tutorial interesting. The SMI module with the latest feature brings new ways how your ERP applications might be used. From sysadmins usage for immediate remote system monitoring without IBM i being exposed outside the local network to features for notifying your clients or field workers.
The latest release with new features will be available to the public on February 19th.