User Tools

Site Tools


sib:listeners:mssqllistener

MSSQLListener

Overview

The MSSQLListener SIB Listener triggers a dataflow depending on rules set on a MSSQL database.

Details

Modulesib_mssqllistener
Version1.3.0

Workflow

  • Subscribe: .custom.schedules[].topic/RESPONSE/#
    • on message:
      • do nothing for now
  • CRONSchedule: [.custom.schedules.schedule]
    • on trigger:
      • custom.handlers.handler()
      • on data Publish: .custom.schedules[x].topic

Custom configuration

mssqllistener/custom.js
let MSSQLListenerCustom = {
	_id: "MSSQLListener:1",
	_name: "SIB MSSQL Listener Sample",
	handlers: {
		testFind: (req, callback)=>{
            req.query("SELECT * FROM table WHERE id=1", (e,r)=>{
                if(e) return callback(null);
                if(r.length == 0) return callback(null);
                callback(r);
            });
		}
	},
	inputFormat: (topic, msg, cb)=>{
		cb(msg);
	},
	loggerCfg: {
		dest: {
			file: false,
			console: true,
			mqtt: true
		}
    },
	mssql: {
		host: "localhost",              // Named instance example: localhost\\SQLEXPRESS
		user: "sibtest",
		password: "sibtest",
		database: "sibtest"
	},
	publishInput: (msg, mqttClient)=>{
		mqttClient.publish(msg._sibheader.topic, JSON.stringify(msg));
	},
	mqtt: "mqtt://localhost",
	schedules: [
		{handler: "testFind", schedule: "* * * * *", topic: "SIB/Samples/MSSQLListener/testFind"}
	],
	topic: "SIB/Samples/MSSQLListener"
};
 
module.exports = MSSQLListenerCustom;
  • _id: The unique ID of this service
  • _name: A plaintext description of this service
  • handlers: An object containing the handler functions that are executed on the CRON triggering, responsible for getting the changed data from the mongoDB and returning that data formatted to fit a message
    • [handlerName](db, callback): Handler method mapped from the schedules config. Parameters passed are the database instance to use and a callback to return data to on the form callback(data)
  • inputFormat(topic, msg, callback): The method that is run on service activation. The original message is passed as the argument and the return value from this method must be a JSON formatted message conforming to the SIB message standard.
  • loggerCfg: A JSON Object defining what logger actions should be active for this service (see Logger Configuration
  • mssql: Database configuration.
    • host: The host of the database server
    • user: The user to log in as
    • password: The base64 encoded password for the user
    • database: The database to connect to
  • publishInput: If defined overrides the standard publishing to the internal MQTT transfer
  • schedules: An array of JSON Objects describing the scheduling and topics to publish messages to
    • schedule: The CRON schedule that decides how often to trigger the data flow
    • topic: The topic to publish the message to
    • handler: The name of the custom.handlers handler to run for this trigger
  • mqtt: The MQTT connection string for the internal MQTT transport
  • topic: The MQTT topic to subscribe to on the internal MQTT transport
sib/listeners/mssqllistener.txt · Last modified: 2019/06/12 08:14 by ozzy