[英]How to catch faust python json serialization error?
I have simple faust agent.我有简单的浮士德代理。 It consumes jsons from kafka topic, and parses them to dicts by default faust serializator:
它使用来自 kafka 主题的 json,并默认将它们解析为 dicts faust 序列化器:
@app.agent(source_topic, sink=[destination_topic])
async def fetch(records):
async for record in records:
result = do_some_stuff(record)
yield result
The deserialization itself happens somewhere outside my code, it managed by faust framework, not by me.反序列化本身发生在我的代码之外的某个地方,它由 faust 框架管理,而不是由我管理。 How I can catch and process deserialization exceptions, eg in case of invalid json?
如何捕获和处理反序列化异常,例如在无效 json 的情况下?
You could manually serialize your data and catch your error:您可以手动序列化数据并捕获错误:
topic = app.topic('custom', value_type=bytes)
@app.agent
async def processor(stream):
async for payload in stream:
data = json.loads(payload)
source: https://faust.readthedocs.io/en/latest/userguide/models.html来源: https://faust.readthedocs.io/en/latest/userguide/models.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.