我是Django和Kafka的新手。我要求在Kafka Consumer中以以下格式获取味精并将其发布到DRF中的视图。以下是我的消息格式和我需要将Kafka消息发布到的我的发布详细信息视图。
My django View to post message :
Msg format send from Kafka Producer
from kafka import KafkaProducer
import json
from bson import json_util
post = []
prod = KafkaProducer(bootstrap_servers='localhost:9092')
while(True) :
title = input("Title :")
content = input("Content :")
author = input ("Author :")
post.append({
"title" : title,
"content" : content,
"author" : author
})
prod.send('hung11898',json.dumps(post, indent=4, default=json_util.default).encode('utf-8'))
prod.flush()
cont = input("Add another Post ?(Y/N)")
if cont == 'N' :
break