User Tools

Site Tools


sib:sib_sequence

SIB Sequence

Overview

The sib_sequence module is a SIB component used to configure message flows in the SIB. Even though it is possible to configure the listeners and callers to chain messages in order to perform complex tasks this often makes the integration flow hard to read. This may be acceptable for smaller integrations with just a few components but for larger and more complex systems it makes maintenance and debugging harder than it needs to be.

The sib_sequence module addresses this by letting all the listeners and callers be individual services without pre-configured interconnections while the sib_sequence contains all the connecting configuration in an easy-to-read format.

Details

Modulesib_sequence
Version1.3.5

Workflow

  • Listen to all the src-topics of the configured maps
    • on message
      • if trig is true
        • push responseTopic to _userData stack
      • if a handle-method is configured
        • run the handle-method on the message
      • Set the messages topic to the configured tgt-topic
      • if this is the last map in the flow
        • set the responseTopic for the message to the responseTopic from the _userData stack
      • else (not the last map)
        • set the responseTopic of the message to the configured rsp-topic, or if not set the src-topic of the next map in the flow
      • if the configured or cond-responded tgt topic is _rsp
        • publish the message to the responseTopic
      • else (not _rsp )
        • publish the message to the configured tgt-topic

Custom configuration

sibsequence/custom.js
module.exports = {
	_id: "sq:1",
	_name: "SIB Sequence demo",
	loggerCfg: {
		dest: {
			mqtt: false,
			file: false,
			console: true
		}
	},
	maps: [{
		_id: "CRON_START",
		src: "SIB/TEST/EVERY30SECONDS",
		tgt: "SIB/TEST/STARTSEQUENCE",
		trig: true
	},{
		_id: "REST_START",
		src: "SIB/TEST/REST",
		tgt: "SIB/TEST/STARTSEQUENCE",
		trig: true
	},{
		_id: "DO_START",
		cond: (map, topic, msg)=>{
			if( msg.data.skipGC ) return "SIB/TEST/MQTT1";
			return "SIB/TEST/GC1";
		},
		src: "SIB/TEST/STARTSEQUENCE",
		tgt: "SIB/TEST/GC1",
		useenv: true
	},{
		_id: "MQTT1",
		src: "SIB/TEST/SQ/MQTT1",
		tgt: "SIB/TEST/MQTT1"
	},{
		_id: "MQTT2",
		src: "SIB/TEST/SQ/MQTT2",
		tgt: "SIB/TEST/MQTT2",
		handle: (t,m,cb)=>{
			m.test = "Handled by handler";
			cb( t, m );
		},
		rsp: "SIB/TEST/OUT"
	}],
	mqtt: "mqtt://localhost"
}
  • _id: The unique ID of this sequence, this value is added to the _sibheader for all messages handled by the sequence
  • _name: A descriptive name of this sequence
  • loggerCfg: A JSON Object defining what logger actions should be active for this service (see Logger Configuration
  • maps: An array containing all the steps in the sequence
    • _id: The unique (within this sequence) ID for this map/step. This value is also added to the _sibheader for traceability.
    • cond (map, topic, msg): Method returning the topic on which to publish this message. If omitted the tgt topic will be used. This method is used for conditional flow control in the sequence.
    • handle( topic, message, callback ): Method that is executed before publishing the message to the tgt-topic. This allows for data transformations to be done in the sequence if needed. If the callback is not called the sequence stops, so this is also useful for flow control.
    • rsp: Default is the src-topic of the next map in the array or the responseTopic of the trig map if the current map is the last configured map. Can be overridden to make the triggered service publish the response somewhere else
    • src: The source topic to listen to, when a message arrives to this topic this map is triggered no matter which service publishes the message
    • tgt: The target topic to publish the message to, triggering the SIB component listening to that topic. If the tgt is “_rsp” the message will be published on the response topic directly, this can be useful on the last node to force a response to the service triggering the sequence
    • trig: boolean, default is false except on the first map where default is true. Tells the sequence that this is the first executed map in the sequence. This value can be overridden for sequences like the example above where one sequence has multiple starting points (triggering maps)
    • useenv: boolean telling the sequence wether to prefix the topics in this map with the environment or not, default true
  • mqtt: The MQTT connection string for the internal MQTT transport
sib/sib_sequence.txt · Last modified: 2019/06/05 07:10 by hubbe