sysid / sse-starlette

BSD 3-Clause "New" or "Revised" License
505 stars 36 forks source link

How can I make pub-sub pattern with sse-starlette? Any suggestion? #14

Closed vaibhavmule closed 3 years ago

vaibhavmule commented 3 years ago

just like this has a queue in this link https://github.com/encode/starlette/issues/20#issuecomment-587410233

Example something like this.

from flask import Flask
from flask_sse import sse

app = Flask(__name__)
app.config["REDIS_URL"] = "redis://localhost"
app.register_blueprint(sse, url_prefix='/stream')

@app.route('/send')
def send_message():
    sse.publish({"message": "Hello!"}, type='greeting')
    return "Message sent!"

so I can use sse.publish anywhere in the code send things like notification to the client?

PS. I am using FastAPI