Producer class

class mdml_client.kafka_mdml_producer(topic, schema=None, config=None, add_time=True, kafka_host='merf.egs.anl.gov', kafka_port=9092, schema_host='merf.egs.anl.gov', schema_port=8081)

Creates a producer instance for producing data to an MDML instance.

Parameters:
  • topic (str) – Topic to send under
  • schema (dict or str) – JSON schema for the message value. If dict, value is used as the schema. If string, value is used as a file path to a json file.
  • config (dict) – Confluent Kafka client config (only recommended for advanced usage - overwrites other parameters)
  • add_time (bool) – If True, adds a value named ‘mdml_time’ to the data object that represents when the producer sent the message
  • kafka_host (str) – Host name of the kafka broker
  • kafka_port (int) – Port used for the kafka broker
  • schema_host (str) – Host name of the kafka schema registry
  • schema_port (int) – Port of the kafka schema registry
flush()

Flush (send) any messages currently waiting in the producer.

produce(data, key=None, partition=None)

Produce data to the supplied topic

Parameters:
  • data (dict) – Dictionary of the data
  • key (str) – String for the Kafka assignor to use to calculate a partition
  • partition (int) – Number of the partition to assign the message to