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”.

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
      • custom.topicFormat
      • 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
        • custom.topicFormat
        • 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",
	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",
	topicFormat: (topic, msg, destTopic)=>{
		return destTopic;
	},
	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
  • 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.
  • 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
  • topicFormat(topic, msg, destTopic): Method that enables customization of external topic name, returns the destination topic on which to publish messages on the external server
  • 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: 2018/12/07 12:56 by hubbe