Configuring Django settings
Ensure that kafkastreamer is present in the INSTALLED_APPS list in the
project settings.py:
INSTALLED_APPS = [
...
"kafkastreamer",
]
The django-kafka-streamer is configured by KAFKA_STREAMER settings variable
which contains such default values:
KAFKA_STREAMER = {
"BOOTSTRAP_SERVERS": None,
"PRODUCER_OPTIONS": {},
"BATCH_SIZE": 500,
"DEFAULT_SOURCE": None,
"DEFAULT_MESSAGE_SERIALIZER": (
"kafkastreamer.serializers.flat_json_message_serializer"
),
"DEFAULT_PARTITION_KEY_SERIALIZER": None,
"DEFAULT_PARTITIONER": None,
}
Configuration settings
BOOTSTRAP_SERVERSList of Kafka services in “host:port” format. For example
["localhost:9092"].PRODUCER_OPTIONSDictionary of additional options passed to the
KafkaProducerconstructor.BATCH_SIZENumber of records in batch.
DEFAULT_SOURCEValue to identify source of data. For example
"mydjangoapp".DEFAULT_MESSAGE_SERIALIZERPath to serializer function in format
"package.module.function". Thekafkastreamer.serializersmodule has one serializer functionflat_json_message_serializerthat used by default. This serializer use model fields names as is, and_prefixed fields for meta data and context extra fields.DEFAULT_PARTITION_KEY_SERIALIZERPath to partition key serializer function. If value
Noneis set (by default) then no partition key will be assigned to messages when streaming. Thekafkastreamer.serializersmodule has one partition key serializer functionobject_id_key_serializerthat use string representation of object ID as partition key.DEFAULT_PARTITIONERPath to partitioner function. If value
Noneis set (by default) then no partitioner will be applied. Thekafkastreamer.partitionersmodule has one partitioner functionmodulo_partitionerthat can by used in combination withobject_id_key_serializerpartition key serializer. Themodulo_partitionerwill distribute messages over partitions based on object ID using formulaobject_id % number_of_partitions.
For details about bootstrap servers, serializers and partitioners see KafkaProducer documentation.