Spring Webflux Async PostgreSQL Publisher Stops After First Result
I created a Postgres Trigger that fires on INSERT
s to my table based on this example:
CREATE OR REPLACE FUNCTION table_update_notify() RETURNS trigger AS $$DECLARE id bigint;BEGIN IF TG_OP = 'INSERT' THEN id = NEW.id; ELSE id = OLD.id; END IF; PERFORM pg_notify('my_trigger_name', json_build_object('table', TG_TABLE_NAME, 'id', id, 'type', TG_OP)::text); RETURN NEW;END;$$ LANGUAGE plpgsql;
Then I subscribed to that Postgres Trigger using reactive-pg-client.Here is the code from their Pub/Sub example:
@BeanPgPool subscribedNotificationHandler() { PgPool client = pgPool(); client.getConnection(asyncResult -> { if (asyncResult.succeeded()) { PgConnection connection = asyncResult.result(); connection.notificationHandler(notification -> { notification.getPayload(); // do things with payload }); connection.query("LISTEN my_trigger_name", ar -> { log.info("Subscribed to channel"); }); } }); return client;}