User Tools

Site Tools


sib:callers:mssqlcaller

MSSQLCaller

Overview

The MSSQL SIB Caller is a specific MSSQL caller that performs operations on a MSSQL database. The caller simply performs the [msg.sql] operation on the database and returns the result. It is recommended to generate the [msg.sql] field in the inputFormat, overwriting whatever value was received from the MQTT transport, for safety reasons. The [msg.sql] field can then be deleted in the outputFormat method if needed.

Details

Modulesib_mssqlcaller
Version1.3.0

Workflow

  • Subscribe: .custom.topic
    • on message:
      • custom.inputFormat
        • if msg.result is set
          • Respond with result from inputFormat
        • else
          • Perform operation on database
          • custom.outputFormat
          • Publish message on responseTopic with the result from the database operation

Custom configuration

mssqlcaller/custom.js
var MSSQLCallerCustom = {
	_id: "mssqlSample:1",
	_name: "MSSQLCallerSample",
	inputFormat: (topic, msg, cb)=>{
		msg.sql = "SELECT * FROM table WHERE field='value'";
		cb(msg);
	},
	loggerCfg: {
		dest: {
			file: false,
			console: true,
			mqtt: true
		}
	},
	mssql: {
		host: "localhost",   // You can use 'localhost\\instance' to connect to named instance
		user: "sibtest",
		password: "base64encodedpw",
		database: "sibtest"
	},
	outputFormat: (topic, msg, cb, mysqlConnection)=>{
		delete( msg.sql );
		cb(msg);
	},
	mqtt: "mqtt://localhost",
	topic: "SIB/test/MSSQLCaller"
};
 
module.exports = MSSQLCallerCustom;
  • _id: The unique ID of this service
  • _name: A plaintext description of this service
  • inputFormat(topic, msg, callback): The method that is run on service activation. The original message is passed as the argument and the input value to the callback must be a JSON formatted message conforming to the SIB message standard. If msg.result is set in the returned message no further database actions will be taken by the caller.
  • loggerCfg: A JSON Object defining what logger actions should be active for this service (see Logger Configuration
  • mssql: 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, base64 encoded
    • database: The database to connect to
  • outputFormat(topic, msg, callback): This message is run on the response data before publishing to the response topic. The response message is passed as the argument and the input to the callback must be a JSON formatted message conforming to the SIB message standard.
  • mqtt: The MQTT connection string for the internal MQTT transport
  • topic: The MQTT topic to subscribe to on the internal MQTT transport
sib/callers/mssqlcaller.txt · Last modified: 2019/06/12 10:30 by ozzy