Please check the given snippet.
Exception throwing properly when no Kafka broker available in the starting stage.
But it's not throwing an exception while disconnecting the Kafka.
from time import sleep
from scrapy_kafka_export.writer import KafkaTopicWriter, \
ScrapyKafkaTopicWriter
item_writer = ScrapyKafkaTopicWriter(
bootstrap_servers="localhost:9092",
topic="my-topic",
batch_size=100,
compression_type=None
)
item = {}
while True:
try:
stats = item_writer.write_item(item)
print(stats)
sleep(5)
except Exception as e:
print(e)