使用faust streamming访问rpc回复中的kafka头

使用faust streamming访问rpc回复中的kafka头,faust,Faust,可以访问faust rpc回复中的kafka头吗? 这是两个浮士德特工的例子。一个(pow)调用另一个(mul)并将结果作为值接收。但是如何知道回复主题中的卡夫卡标题呢 #!/usr/bin/env python from typing import AsyncIterable import faust from faust import StreamT app = faust.App('RPC99', reply_create_topic=True) pow_topic = app.topi

可以访问faust rpc回复中的kafka头吗? 这是两个浮士德特工的例子。一个(
pow
)调用另一个(
mul
)并将结果作为值接收。但是如何知道回复主题中的卡夫卡标题呢

#!/usr/bin/env python
from typing import AsyncIterable
import faust
from faust import StreamT

app = faust.App('RPC99', reply_create_topic=True)
pow_topic = app.topic('RPC__pow')
mul_topic = app.topic('RPC__mul')

@app.agent(pow_topic)
async def pow(stream: StreamT[float]) -> AsyncIterable[float]:
    async for value in stream:
        yield await mul.ask(value=value ** 2)
        # Headers for the returning result here?

@app.agent(mul_topic)
async def mul(stream: StreamT[float]) -> AsyncIterable[float]:
    async for value in stream:
        yield value * 100.0

流事件似乎有一个
headers
类型为
Union[List[Tuple[str,bytes]]
的属性

他们在这里有,但目前还没有详细说明这一点

看起来你可以像这样做

@app.agent(topic)
async def process(stream):
    async for value in stream:
        do_something(value.headers)
如果您已经对消息进行了反序列化,那么您似乎还可以通过via
faust.streams.current\u event()
访问原始事件

编辑以下内容以回应ааааааа的评论:


看起来您必须显式发送消息才能修改标头。请查看中的
send()
函数签名。我认为
send
或该类中的其他send变体之一应该是您要查找的内容。

您可以从从以下接收到的事件中获取标头:

stream.events()

faust.types.events的定义:


是的,我知道我可以从stream.events()或使用current_event()访问它们。但是传入消息的这些状态。我正在询问回复。
ask()
方法也有
标题
@app.agent(topic)
async def iterrate(stream):
    async for event in stream.events():
        value = event.value
        offset = event.message.offset
        headers = event.headers