NAME
IO::Async::Pg::PubSub - PostgreSQL LISTEN/NOTIFY pub/sub
SYNOPSIS
my $pubsub = $pg->pubsub;
# Subscribe to a channel
await $pubsub->subscribe('my_channel', sub {
my ($channel, $payload, $pid) = @_;
print "Got notification: $payload\n";
});
# Publish to a channel
await $pubsub->notify('my_channel', 'Hello World');
# Unsubscribe
await $pubsub->unsubscribe('my_channel');
DESCRIPTION
This module provides PostgreSQL LISTEN/NOTIFY support for pub/sub messaging.
Note: This is in-memory only. For multi-server deployments, use an external message broker like Redis.
METHODS
subscribe($channel, $callback)
Subscribe to a channel. The callback is called with ($channel, $payload, $pid).
unsubscribe($channel, [$callback])
Unsubscribe from a channel. If callback is provided, only that callback is removed; otherwise all callbacks for the channel are removed.
notify($channel, [$payload])
Send a notification to a channel with optional payload.
disconnect
Disconnect from the database and clean up.
AUTHOR
John Napiorkowski <jjn1056@yahoo.com>