supabase / realtime

Broadcast, Presence, and Postgres Changes via WebSockets
https://supabase.com/realtime
Apache License 2.0
6.82k stars 315 forks source link

feat: Support LISTEN broadcast in Realtime #1086

Closed filipecabaco closed 4 months ago

filipecabaco commented 4 months ago

What kind of change does this PR introduce?

Support LISTEN/NOTIFY on realtime:broadcast which allows users to trigger broadcast messages by sending a payload to this topic.

select pg_notify(
          'realtime:broadcast',
          json_build_object(
              'private', $1::boolean,
              'topic', $2::text,
              'event', $3::text,
              'payload', $4::jsonb
          )::text
      );

We want to keep it as close to the Broadcast endpoint as possible and it already includes the feature flag notify_private_alpha to enabled it (defaults to false)

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **realtime-demo** | ⬜️ Ignored ([Inspect](https://vercel.com/supabase/realtime-demo/85gD5Z3bjtrCzXjJos6KPsLEocpP)) | [Visit Preview](https://realtime-demo-git-feat-pg-listen-to-broadcast-supabase.vercel.app) | | Jul 10, 2024 11:51pm |
abc3 commented 4 months ago

@filipecabaco when does the Listen connection stop?

filipecabaco commented 4 months ago

@filipecabaco when does the Listen connection stop?

The processes are linked so I would expect it to stop the connection but worth to check! I will try to do a test to check the behaviour for sanity sake 👍

filipecabaco commented 4 months ago

@abc3 good call on the test, without restart: :transient we had the process auto restart wrongly, added a test to check what happens when we suspend a tenant (which kills conns)

kiwicopple commented 4 months ago

:tada: This PR is included in version 2.30.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

psteinroe commented 4 months ago

just saw this on my timeline, and I think it should be noted in the docs for this that there is a relatively low limit on the notify payload size.

filipecabaco commented 4 months ago

@psteinroe yes, 8kb. we want to give a new channel of communication that is more native to the database vs pg_net

we'll need to be careful to properly explain in the docs and this won't be launched for a while as this will be "private alpha" and feature flagged