Skip to the content.

Topology definition

Topology is defined via JSON. It follows this structure:

An example:

{
    "general": {
        "heartbeat": 3200,
        "initialization": [
            { "working_dir": ".", "cmd": "init.js" }
        ],
        "shutdown": [
            { "working_dir": ".", "cmd": "shutdown.js" }
        ]
    },
    "spouts": [
        {
            "name": "pump1",
            "type": "inproc",
            "working_dir": ".",
            "cmd": "spout_inproc.js",
            "init": {}
        },
        {
            "name": "pump2",
            "type": "module_class",
            "working_dir": "some-module",
            "cmd": "TargetClass",
            "init": {}
        }
    ],
    "bolts": [
        {
            "name": "bolt1",
            "working_dir": ".",
            "type": "inproc",
            "cmd": "bolt_inproc.js",
            "subtype": "subtype1",
            "inputs": [{ "source": "pump1" }],
            "init": {}
        },
        {
            "name": "bolt2",
            "working_dir": ".",
            "type": "inproc",
            "cmd": "bolt_inproc.js",
            "inputs": [
                { "source": "pump1" },
                { "source": "pump2", "stream_id": "stream1" }
            ],
            "init": {
                "forward": true
            }
        },
        {
            "name": "bolt3",
            "working_dir": ".",
            "type": "inproc",
            "cmd": "bolt_inproc.js",
            "inputs": [{ "source": "bolt2" }],
            "init": {
                "forward": false
            }
        },
        {
            "name": "bolt4",
            "working_dir": "some-module",
            "type": "module_method",
            "cmd": "methodName",
            "subtype": "some-name",
            "inputs": [{ "source": "bolt2" }],
            "init": {
                "forward": false
            }
        }
    ],
    "variables": {}
}

Topology can be validated using built-in validator:

"use strict";

let config = {....};

// Run validator and abort process if topology doesn't meet the schema.
const validator = require("qtopology").validation;
validator.validate({ config: config, exitOnError: true });

Notes

Passing binary messages or not?

Use this option at your own risk. You have to explicitly enable it.

If messages are passed in binary form, there is a chance that one of the subsequent nodes changes the messages and this change will be visible to all other nodes. There is no isolation between the siblings. Also, there is no guarantied order of execution between siblings and their children.

So, when should we use it? When all of the following assumptions are true: