User Tools

Site Tools


sib:callers:mqttcaller

MQTTCaller

Overview

The MQTTCaller SIB Caller is a specific MQTT caller that publishes messages to, and receives responses from, an external MQTT service, where external is in the meaning of “not the internal SIB MQTT transport”.

Details

Modulesib_mqttcaller
Version1.3.4

Workflow

  • Subscribe: .custom.topic
    • on message:
      • Store the topic and responsetopic in the _sibheader._store for later use
      • Update the SIBHeader for the external call, setting the correct responseTopic
      • custom.inputFormat
      • Publish: Reformatted .custom.dest.topic
  • Subscribe: .custom.topic/REQUEUE
    • on message:
      • if message is a response message
        • .custom.outputFormat
        • Restore topic and responseTopic from _sibheader._store
        • Publish: msg._sibheader.responseTopic
      • if message is an input message
        • Store the topic and responseTopic in the _sibheader._store for later use
        • Update the SIBHeader for the external call, setting the correct responseTopic
        • custom.inputFormat
        • Publish: Reformatted .custom.dest.topic
  • Subscribe: .custom.dest.topic/RESPONSE/#
    • on message:
      • .custom.outputFormat
      • Restore topic and responseTopic from _sibheader._store
      • Publish: msg._sibheader.responseTopic

Custom configuration

generalcaller/custom.js
var MQTTServiceCustom = {
	_id: "mqttCaller:1",
	_name: "SIB MQTT Caller Sample",
	init: ( thisCaller )=>{},
	inputFormat: (topic, msg, callback)=>{
		msg.fmtData = "Data has been formatted and modified";
		callback(msg, {});
	},
	loggerCfg: {
		dest: {
			file: false,
			console: true,
			mqtt: true
		}
	},
	outputFormat: (topic, msg, callback)=>{
		msg.outData = "output sent";
		callback( msg );
	},
	mqtt: "mqtt://localhost",
	dest: {
		mqtt: "mqtt://localhost",
		topic: "EXTERNAL/TEST/SIB/MQTTCALLER",
		useenv: false
	},
	topic: "SIB/Samples/MQTTCaller"
};
 
module.exports = MQTTServiceCustom;
  • _id: The unique ID of this service
  • _name: A plaintext description of this service
  • init(thisCaller): If defined this method is executed when the service is starting up as the last step of initialization. thisCaller is a reference to the instance of the caller 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 input value to the callback must be a JSON formatted message conforming to the SIB message standard. An optional second argument was added to the callback in version 1.3.4 options being the same options parameter as used in the mqtt.publish method.
  • loggerCfg: A JSON Object defining what logger actions should be active for this service (see Logger Configuration
  • 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
  • dest: Configuration of the destination MQTT provider
    • mqtt: Connection string to the external MQTT server
    • topic: Topic on which to publish messages, will be passed as the destTopic argument to topicFormat method if implemented
    • useenv: Boolean, default false. If set to true the dest.topic will be prepended with the current process.env.NODE_ENV as all the internal MQTT topics are
  • topic: The MQTT topic to subscribe to on the internal MQTT transport
sib/callers/mqttcaller.txt · Last modified: 2020/01/15 15:49 by hubbe