本例子介绍 python kafka producer发送数据consumer 接收,并且写入redis简单步骤
kafka-python-producer.py
producer 来发送数据,更新时间戳,ID自增长。5秒发送一次
#!/usr/bin/python
# -*- coding:utf-8 -*-
#kafka-python-producer
from kafka import KafkaProducer
from kafka.errors import KafkaError
import json
import time
import datetime
producer = KafkaProducer(bootstrap_servers=['localhost:9092'])
HEAD_ID='WP'
ID=2020016300386
while True:
date=datetime.datetime.strftime(datetime.datetime.now(),"%Y-%m-%d %H:%M:%S")
d={"relateOrder":"1169141000","subSectionCode":"","dealEmpId":"","eventCase":"","isService":"否","eventObject":"物流公司","omsOrderItemId":"00024877154601","eventSource":"LMA","eventCode":"02","isComplain":"否","eve