dojot.module package

Submodules

dojot.module.auth module

dojot.module.config module

Configuration data module

class dojot.module.config.Config(config=None)

Bases: object

Main configuration class

This class contains all needed configuration for this library

__init__(config=None)

Config constructor

Parameters:config (dict or None) – A configuration dictionary. If set, all its attributes will be set to this object.

Any top level key will overwrite the default configuration, i.e., setting a kafka object to config param will overwrite all Kafka configuration. An example of such dictionary is:

config = {
    "kafka" : {
        "producer": {
            "client.id": "kafka",
            "metadata.broker.list": "kafka:9092",
            "compression.codec": "gzip",
            "retry.backoff.ms": 200,
            "message.send.max.retries": 10,
            "socket.keepalive.enable": True,
            "queue.buffering.max.messages": 100000,
            "queue.buffering.max.ms": 1000,
            "batch.num.messages": 1000000,
            "dr_cb": True
        },
        "consumer": {
            "group.id": "my-module",
            "metadata.broker.list": "kafka:9092"
        }
    }
    "data_broker" : {
        "url": "http://data-broker"
    }

    "auth" : {
        "url": "http://auth:5000",
        "timeout_sleep": 5,
        "connection_retries": 3
    }

    "dojot" : {
        "management": {
            "user" : "dojot-management",
            "tenant" : "dojot-management"
        },
        "subjects": {
            "tenancy": "dojot.tenancy",
            "devices": "dojot.device-manager.device",
            "device_data": "device-data,
        }
    }
}

Warning

If set, the dojot section should be in sync with all other modules. Otherwise this module won’t work properly.

Note

The Kafka object is straight from librdkafka configuration, separated into producer and consumer subobjects. For more information about this configuration, you should check its documentation.

load_defaults()

Load default configuration, which is:

kafka:
    producer:
        client.id: "kafka"
        metadata.broker.list: "kafka:9092"
        compression.codec: "gzip"
        retry.backoff.ms: 200
        message.send.max.retries: 10
        socket.keepalive.enable: True
        queue.buffering.max.messages: 100000
        queue.buffering.max.ms: 1000
        batch.num.messages: 1000000
        dr_cb: true
    consumer:
        group.id: "my-module"
        metadata.broker.list: "kafka:9092"
data_broker:
    url: "http://data-broker"
auth:
    url: "http://auth:5000"
    timeout_sleep: 5
    connection_retries: 3
dojot:
    management: 
        user: "dojot-management"
        tenant: "dojot-management"
    subjects:
        tenancy: "dojot.tenancy"
        devices: "dojot.device-manager.device"
        device_data: "device-data"

Warning

Calling this function will overwrite any previously set configuration in the created object. Also setting any configuration after Kafka is started or any Messenger object is created will have no effect on them.

Warning

If set, the dojot section should be in sync with all other modules. Otherwise this module won’t work properly.

load_env()

Load configuration from environment variables.

Any environment variable will overwrite the default configuration. Check load_defaults() function.

The list of envirnoment variables is:

  • KAFKA_HOSTS: a comma-separated list of hosts where an instance of Kafka is running. This will affect the metadata.broker.list parameter for both Kafka consumer and producer.
  • KAFKA_GROUP_ID: The Kafka consumer group ID to be used.
  • DATA_BROKER_URL: Where DataBroker service can be reached.
  • AUTH_URL: Where Auth service can be reached.
  • DOJOT_MANAGEMENT_TENANT: tenant to be used when asking DataBroker for management topics (such as tenancy-related topics)
  • DOJOT_MANAGEMENT_USER: user to be used when asking DataBroker for management topics (such as tenancy-related topics)
  • DOJOT_SUBJECT_TENANCY: Subject to be used when asking DataBroker for tenancy topics.
  • DOJOT_SUBJECT_DEVICES: Subject to be used when asking DataBroker for device topics.
  • DOJOT_SUBJECT_DEVICE_DATA: Subject to be used when asking DataBroker for device data topics.

dojot.module.logger module

dojot.module.messenger module

dojot.module contents