Skip to content
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

I can't change the channel always trigger the default "EventNotifier" #81

Open
jorgeav527 opened this issue Aug 1, 2024 · 1 comment

Comments

@jorgeav527
Copy link

from fastapi_websocket_pubsub import PubSubEndpoint
from pydantic import BaseModel
from datetime import datetime


class ActivityLog(BaseModel):
    channel: str
    action: str
    user_id: str
    created: datetime


endpoint = PubSubEndpoint(
    broadcaster="redis://user:password@host:port"
)


@shared_router.websocket("/pubsub")
async def websocket_rpc_endpoint(websocket: WebSocket):
    await endpoint.main_loop(websocket)


@shared_router.post("/publish")
async def post_to_redis_pubsub(simple_message: ActivityLog):
    await endpoint.publish(
        topics=[simple_message.channel], data={"user_id": simple_message.user_id, "created": simple_message.created}
    )
    return {"message": "Event published"}

when I run the endpoint with swagger or curl

curl -X 'POST' \
  'http://localhost:7777/shared/publish' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "channel": "string",
  "action": "string",
  "user_id": "string",
  "created": "2024-08-01T18:26:07.523Z"
}'

the message is successfully sent but the channel do not change this I could see on the redis insight

Timestamp: 13:26:17 01 Aug 2024
Channel: "EventNotifier"
Message: {"notifier_id":"e07a909adf6d44dea3e9ab1df25cf1cd","topics":["string"],"data":{"user_id":"string","created":"2024-08-01T18:26:07.523000Z","channel":"string"}}
@orweis
Copy link
Contributor

orweis commented Aug 1, 2024

Hi, not sure what you're trying to do.
The story here is missing clients/subscribers that would receive the event.
Note the broadcaster with Redis is only meant to propagate the message to more PubSub servers (and through them to their clients) - it is usually not needed if you're not scaling out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants