Replies: 2 comments 4 replies
-
Hello! None of questions you've asked apply to the Broadcaster itself ;) Broadcaster is small library that provides unified API over the top of few technologies that support publish-subscribe model. This library only does three things:
Everything else has to be implemented by the developer and is outside of this library's scope. If you take example's code and remove lines of code non-specific to the broadcaster, you will get this: # Creates pub-sub service using Redis
broadcast = Broadcast("redis://localhost:6379")
# Sends "message" to the "chatroom" channel
await broadcast.publish(channel="chatroom", message=message)
# Receives messages sent to the "chatroom" channel and does something with them
async with broadcast.subscribe(channel="chatroom") as subscriber:
async for message in subscriber:
do_something_with_message(message) I'm sorry I'm unable to provide the example for FastAPI at this time, but hopefully this will make it little more clear what this library is and what it's not. :) |
Beta Was this translation helpful? Give feedback.
-
Right, right - definitely not directly related, so it's mostly an out-of-scope question. And thanks for the quick response! Maybe I'll just follow-up here in case someone else has the same question, as the FastAPI Websockets docs points here, and it's not clear how to fit I'll take a stab at using this on a project, then post a sample implementation here if I get it working. |
Beta Was this translation helpful? Give feedback.
-
Sorry for the newbishness, I'm having trouble understanding how to use the project. Main points I struggle with:
Depends(...)
injected to routes. They usefastapi.app.websocket
rather thanstarlette.routing.WebSocketRoute
. Wondering what the simple translation from Starlette->FastAPI is to allowDepends()
in the functions?WebSocketRoute("/", ...)
withapp.websocket("/")
, where do I put my dependencies? Is it at theasync def chatroom_ws(websocket, <add deps here>)
level?on_connect
,on_disconnect
?run_until_first_complete
? I can't find documentation in Starlette, and when I dive intoasyncio.wait(..., FIRST_COMPLETED)
it seems to imply the first task to complete is solid, and what's left is cancelled? Which confuses me on the setup of receiver/sender, don't we want both?WebSocketEndpoint
withon_connect|disconnect|message
, keeping websockets around for later use, etc. Maybe a more robustbroadcaster
sample in/examples
could be in order for us FastAPI newbies?Beta Was this translation helpful? Give feedback.
All reactions