![](/img/trans.png)
[英]how to get acknowledgement from Kafka broker if message is produced by producer?
[英]How to consume message from kafka which was produced by kafka-python?
我想獲得有關 kafka 的幫助。
是否可以使用由kafka-python生成的kafka-console-consumer.sh
來使用 utf8(日語)消息?
self._client = KafkaProducer(\
bootstrap_servers=bootstrap_servers,\
api_version=api_version,\
value_serializer=lambda m: json.dumps(m).encode('utf-8'))
for message in data:
self._client.send(topic, message)
./kafka-console-consumer.sh --bootstrap-server msk.amazonaws.com:9092 --topic meetings --from-beginning --property value.deserializer=org.apache.kafka.common.serialization.BytesDeserializer
"uuid": "d/U55wRdSj60yJBcYVpt8A==", "id": 4459052115, "topic": "\x5Cu6e21\x5Cu8fba \x5Cu88d5\x5Cu306e\x5Cu30d1\x5Cu30fc\x5Cu30bd\x5Cu30ca\x5Cu30eb\x5Cu30df\x5Cu30fc\x5Cu30c6\x5Cu30a3\x5Cu30f3\x5Cu30b0\x5Cu30eb\x5Cu30fc\x5Cu30e0", "host": "\x5Cu6e21\x5Cu8fba \x5Cu88d5", "email": "y-watanabe@creationline.com", "user_type": "\x5Cu30e9\x5Cu30a4\x5Cu30bb\x5Cu30f3\x5Cu30b9\x5Cu6e08\x5Cu307f", "start_time": "2020-11-03T10:36:29Z", "end_time": "", "duration": "", "participants": 1, "has_pstn": false, "has_voip": false, "has_3rd_party_audio": false, "has_video": false, "has_screen_share": false, "has_recording": false, "has_sip": false, "dept": ""}
似乎日語字符串(utf-8)沒有正確反序列化。 它已損壞。
我正在嘗試通過以下路線發送消息。
producer(kafka-python) -> AWS MSK (2.4.1.1) -> consumer(kafka-console-consumer.sh)
我有幾件事我沒有正確理解。
將字節數組中的記錄值反序列化為值或對象。
如果 ensure_ascii 為真(默認值),則輸出保證所有傳入的非 ASCII 字符都被轉義。 如果 ensure_ascii 為 false,則這些字符將按原樣輸出。
通過將ensure_ascii設置為False
然后轉換為byte ,解決了這個問題。
producer = KafkaProducer(bootstrap_servers=['localhost:9092'], value_serializer=lambda m: json.dumps(m, ensure_ascii=False).encode('utf-8'))
涉及到
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.