-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: using routers, publishers do not handle batch return from handlers #1945
Comments
I tried to reproduce your problem, but seems like it is working fine from faststream import FastStream
from faststream.kafka import KafkaBroker, KafkaPublisher, KafkaRoute, KafkaRouter
broker = KafkaBroker()
app = FastStream(broker)
async def handler(msgs: list[int]):
print(msgs)
return tuple(msgs)
router = KafkaRouter(
handlers=(
KafkaRoute(
handler,
"in",
batch=True,
publishers=(KafkaPublisher("out", batch=True),),
),
KafkaRoute(
handler,
"out",
batch=True,
),
)
)
broker.include_router(router)
@app.after_startup
async def _():
await broker.publish_batch(*list(range(3)), topic="in") Handler consumes |
Sorry, I should check confluent instead 😄 |
I tested the code on faststream.confluent and everything works. from faststream import FastStream
from faststream.confluent import KafkaBroker, KafkaRouter, KafkaRoute, KafkaPublisher
import asyncio
broker = KafkaBroker()
app = FastStream(broker)
async def handler(messages):
print(f'first: {messages}')
return tuple(messages)
async def second_handler(messages: set[str]):
print(messages)
router = KafkaRouter(
handlers=(
KafkaRoute(
handler,
"topic_in_issue_1945",
batch=True,
auto_offset_reset="earliest",
publishers=(KafkaPublisher("topic_out_issue_1945", batch=True),),
),
KafkaRoute(
second_handler,
"topic_out_issue_1945",
batch=True
)
)
)
@app.after_startup
async def t():
await asyncio.sleep(5)
await broker.publish_batch("test batch return", "test second batch return", topic="topic_in_issue_1945")
async def start_app():
await app.run()
asyncio.run(start_app())
|
Thx @spataphore1337 , will try and run your reproduction later today. |
@spataphore1337, compared the code with mine, and highlighted the difference below. second_handler receives a async def second_handler(messages: str) #set[str]):
print(messages)
...
KafkaRoute(
second_handler,
"topic_out_issue_1945",
# batch=True
) |
Interestingly, when I run on my local (Macos), the behavior is correct: 3 messages in, 3 messages out. When deployed to a Docker container on linux, I get 3 messages in, 1 list message out. A bit puzzled atm, as I cannot reproduce on my local. |
Describe the bug
When using KafkaRouter and KafkaRoute publishers, publisher does not handle properly the tuple returned by handler function.
How to reproduce
Include source code:
Expected behavior
If 3 messages are received from topic_in by batch by
handler
function, 3 messages are pushed to topic_out.Observed behavior
If 3 messages are received from topic_in by batch by
handler
function, 1 message is pushed to topic_out (the message is a list of the 3 messages received in function input).Screenshots
Environment
Running FastStream 0.5.30 with CPython 3.12.7 on Darwin
Additional context
Provide any other relevant context or information about the problem here.
The text was updated successfully, but these errors were encountered: