dojot.module.kafka package

Submodules

dojot.module.kafka.consumer module

Kafka consumer module

class dojot.module.kafka.consumer.Consumer(config, name=None)

Bases: threading.Thread

Kafka consumer

__init__(config, name=None)

Builds a new Consumer

It is important to realize that the kafka.consumer and kafka.producer configuration are directly passed to node-rdkafka library (which will forward it to librdkafka). You should check `its documentation<https://github.com/edenhill/librdkafka/blob/0.11.1.x/CONFIGURATION.md>`_ to know which are all the possible settings it offers.

Parameters:
  • config (Config) – The configuration object
  • name (str) – A name for this consumer.
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

stop()

Stop this consumer

It won’t be stopped right away, be advised.

subscribe(topic, callback)

Subscribe to a list of topics

This function will add a new topic to the topics which this consumer is subscribed to.

Parameters:
  • topic (str) – new topic
  • callback (function) – Function to be called whenever a new message is received.

This method should not thrown any exceptions. No processing is done with its results.

dojot.module.kafka.producer module

Kafka producer

class dojot.module.kafka.producer.Producer(config)

Bases: object

Kafka producer

init()

Producer initialization

This function will create the KafkaProducer.

produce(topic, msg)

Produce a message to a Kafka topic

Parameters:
  • topic (str) – The topic to which the message will be published.
  • msg (str) – The message to be published

dojot.module.kafka.topic_manager module

Topic manager

class dojot.module.kafka.topic_manager.TopicManager(config)

Bases: object

Class that deals with DataBroker topics

static get_key(tenant, subject)

Return a key to be associated with a particular Kafka topic

Parameters:
  • tenant (str) – The tenant to be used
  • subject (str) – The subject to be used
Return type:

str

Returns:

The key to be used

get_topic(tenant, subject, global_val='')

Retrieves a topic from DataBroker

Parameters:
  • tenant (str) – The tenant associated to the topic being retrieved
  • subject (str) – The subject associated to the topic being retrieved
  • global_val (bool) – True if this topic should be a global one.
Return type:

str

Returns:

The topic

Module contents

Kafka related modules