User Tools

Site Tools


sib:listeners:socketlistener

SocketListener

Overview

The SocketListener connects to a socket and publishes any incoming data on that socket. When data is received it is transformed to a SIB message and triggers the workflow.

Workflow

  • Establish connection to the server using custom.endpoint.host and custom.endpoint.port
    • on incoming data:
      • convert buffer to utf8 string
      • add data to SIBMessage
      • apply SIBHeader
      • Publish: .custom.topic
  • Subscribe: .custom.topic/REQUEUE
    • on message:
      • custom.inputFormat
      • Publish: msg._sibheader.topic

Custom configuration

socketlistener/custom.js
var SocketListenerCustom = {
    _id: "SIBSample:1",
    _name: "My Socket listener",
    endpoint: {
        DEV: { host: "hostname", port: "2000" },
        TEST: { host: "hostname", port: "4000" },
        QA: { host: "hostname", port: "6000" },
        PROD: { host: "hostname", port: "8000" }
    },
    inputFormat: (topic, msg, cb)=>{    
        callback(msg);
    },
    publishInput: (msg, mqtt)=>{
        mqtt.publish(msg._sibheader.topic, JSON.stringify(msg));
    },
    loggerCfg: {
        dest: {
            file: false,
            console: true,
            mqtt: true
        }
    },
    mqtt: "mqtt://localhost",
    mqtt_timeout: 20000,
    topic: "TOPIC/TO/PUBLISH"
};
 
module.exports = SocketListenerCustom;
  • _id: The unique ID of this service
  • _name: A plaintext description of this service
  • endpoint.host: Host to connect to
  • endpoint.port: Port on host
  • inputFormat(topic, msg, cb): 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
  • mqtt: The MQTT connection string for the internal MQTT transport
  • mqtt_timeout: Number of milliseconds to wait for a response on the MQTT transport before sending a timeout response to the REST Client
  • publishInput: If defined overrides the standard publishing to the internal MQTT transfer
  • topic: The MQTT topic to publish to on the internal MQTT transport
sib/listeners/socketlistener.txt · Last modified: 2019/02/22 14:08 by ozzy