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

No notifications received with Postgres as backend #53

Open
wkamer opened this issue Sep 22, 2021 · 4 comments
Open

No notifications received with Postgres as backend #53

wkamer opened this issue Sep 22, 2021 · 4 comments

Comments

@wkamer
Copy link

wkamer commented Sep 22, 2021

I'm trying to get broadcaster work with FastAPI and a PostgreSQL database with notifications enabled.

Here is the code I use

FastAPI (test_broadcaster.py)

from broadcaster import Broadcast

broadcast = Broadcast("postgres://<username>:<password>@localhost:5432/<database>")

async def broadcast_ws_receiver(websocket):
    async for message in websocket.iter_text():
        await broadcast.publish(channel="account", message=message)

async def broadcast_ws_sender(websocket):
    async with broadcast.subscribe(channel="account") as subscriber:
        async for event in subscriber:
            await websocket.send_text(event.message)

FastAPI (router.py)

from fastapi.routing import APIRouter
from fastapi.websockets import WebSocket
from fastapi.concurrency import run_until_first_complete

from test_broadcaster import broadcast_ws_sender, broadcast_ws_receiver

router = APIRouter()

@router.websocket("/broadcast")
async def broadcast_ws(websocket: WebSocket):
    await websocket.accept()
    
    await run_until_first_complete(
        (broadcast_ws_receiver, {"websocket": websocket}),
        (broadcast_ws_sender, {"websocket": websocket}),
    )

PostgreSQL (trigger name) # on the table account
account

PostgreSQL (trigger_function)

BEGIN
  PERFORM pg_notify(
    'account',
    json_build_object(
      'operation', TG_OP,
      'record', row_to_json(NEW)
    )::text
  );

  RETURN NEW;
END;

When making the websocket connection connection and update the table to trigger a notification, nothing happends. Also not when using

NOTIFY account, 'hello world';

When changing to Redis it is working flawless, from Redis to websocket and websocket to Redis.

Is this a bug? Or I'm missing something in the code?

@wkamer
Copy link
Author

wkamer commented Sep 25, 2021

Is this tool still under development? Hope to get some response.

@AntonOfTheWoods
Copy link

@wkamer, it's worse than that, the maintainers don't even have the respect to put a message in the readme saying that it is no longer under development, in spite of lots of people submitting issues and PRs...

@tomchristie
Copy link
Member

Hi folks - if you've a PR that you'd like to see merged that's currently blocked then let me know and I can add you to the maintainers team.

@wkamer - Don't know - I'm not currently using broadcaster myself, so depends if anyone in the community who's currently using broadcaster w/ postgres is able to chime in on the thread? (Or else whatever you're able to dig into yourself and fill in on, here.)

@rafalp
Copy link
Member

rafalp commented Oct 7, 2021

I'm using broadcaster with Redis backend and it works fine, but AFAIR that's only backend that does. Something is very wrong with our tests suite IMHO. It's supposed to test other backends like memory, Kafka and PostgreSQL and tests for those pass, but in real world suddenly they don't.

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

4 participants