User Tools

Site Tools




The mySQLListener SIB LIstener triggers a dataflow depending on rules set on a mySQL database.




  • 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

let mySQLListenerCustom = {
	_id: "mySQLListener:1",
	_name: "SIB mySQL Listener Sample",
	handlers: {
		firstCheck: (connection, callback)=>{
			connection.query( "SELECT * FROM test WHERE _show=1", (e,r)=>{
				if( e ) return callback( null );
				if( r.length == 0 ) return callback(null);
				connection.query( "UPDATE test SET _show=0", ()=>{
					callback( r );
				} );
	init: ( thisListener )=>{},
	inputFormat: (topic, msg, cb)=>{
	msg._sibheader.topic = "TEST/TEST";
	loggerCfg: {
		dest: {
			file: false,
			console: true,
			mqtt: true
	mysql: {
		host: "localhost",
		user: "sibtest",
		password: "sibtest",
		database: "sibtest"
	publishInput: (msg, mqttClient)=>{
		mqttClient.publish( msg._sibheader.topic, JSON.stringify( msg ) );
	mqtt: "mqtt://localhost",
	schedules: [
		{handler: "firstCheck", schedule: "* * * * * *", topic: "SIB/Samples/mySQLListener/firstCheck"}
	topic: "SIB/Samples/mySQLListener"
module.exports = mySQLListenerCustom;
  • _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)
  • init(thisListener): If defined this method is executed when the service is starting up as the last step of initialization. thisListener is a reference to the instance of the listener that does the method call.
  • 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
  • mysql: Database configuration. The below fields are required but everything that can be passed to mysql.connect can be set here
    • host: The host of the database server
    • user: The user to log in as
    • password: The 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/mysqllistener.txt · Last modified: 2019/10/02 08:26 by hubbe