Open harochau opened 1 year ago
faust-streaming has aiohttp embedded in it and you should use that instead of fast-api
aiohttp
faust.web
(aiohttp) anyway and let users plug-in any framework they likeI have Faust services where I only use built-in aiohttp for web interface, but it is cumbersome at best.
After some instigation, I was able to make my services work with 0.10.2, 0.10.3, 0.10.4 versions I need to start my fastapi app from command line or from separate python file like run.py, not from fastapi_app.py Moving the code snippet blow from fastapi_app.py to separate python file like run.py and changing entry point seem to fix the issue. Probably it's because of double import and double creation of faust app/kafka producer.
if __name__ == "__main__":
import uvicorn
uvicorn.run('fastapi_app:app', host=..., port=..., reload=True)
I guess the changes from 0.10.2 should be at least a minor patch, as it breaks some workflows.
Thanks for pursuing this, I'll take a stab at expanding upon a better solution in https://github.com/faust-streaming/faust/blob/master/examples/fastapi_example.py.
I do think that we should explore replacing aiohttp
with fastapi
. It's just a matter of finding the time to do so...
Thanks for all the people continuing to support this project, unfortunately I run into a critical bug in my system:
Checklist
master
branch of Faust.Steps to reproduce
python faust_app.py worker -l info
Expected behavior
I can import a topic created in faust_app.py into fastapi_app.py and use
await my_topic.send(value={...})
inside of FastAPI async endpoints (or use an async function that does the same). Everything works OK in faust-streaming version 0.10.1 and below.Actual behavior
AssertionError: Please create objects with the same loop as running with
orRuntimeError: Task attached to a different loop
looks like the 1st attempt will result in the 1st error, and further attempts result in the second error.Full traceback
in production k8s
in local docker-compose
Versions
python:3.11-slim
)image: confluentinc/cp-kafka:7.0.0