SupabaseS
Supabase7mo ago
volfpe

Realtime Broadcast events are not received when sent from database trigger

Hello. This is my database trigger that broadcasts the message:
CREATE OR REPLACE FUNCTION public.messages_broadcast_changes()
 RETURNS trigger
 LANGUAGE plpgsql
 SECURITY DEFINER
AS $function$
begin
  if coalesce(NEW.job_id, OLD.job_id) is not null then
    perform realtime.broadcast_changes(
      'test',
      TG_OP,                                                -- event: INSERT/UPDATE/DELETE
      TG_OP,                                                -- operation: same as event
      TG_TABLE_NAME,                                        -- table
      TG_TABLE_SCHEMA,                                      -- schema: public
      NEW,                                                  -- new record
      OLD                                                   -- old record
    );
  end if;
  
  return null;
end;
$function$
;


The trigger gets called and it successfully creates a new row in realtime.messages table with the test topic and correct data. However, I'm not able to receive the event in my client application. Even when using the realtime inspector with the service role, the event won't show up in the UI.

When sending the event from the realtime inspector (using the "Broadcast a message" button), the client receives the event.

I'm using the private channel and I simplified the Policy to allow everything.
Was this page helpful?