Skip to content

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

Description

@jorgeav527
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"}}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions