lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
8.86k stars 908 forks source link

1 Listener for 2 channel #1139

Open septiyanmudhiya502 opened 9 months ago

septiyanmudhiya502 commented 9 months ago

Is it possible to use 1 listener to listen to 2 different channel ? Currently I'm using 1 same listener instance in 2 different service and both of them listen to different channel, however notification from channel 1 is received in instance 2.

johto commented 8 months ago

You can listen an arbitrary number of PostgreSQL listen channels on a single pq.Listener. But all notifications will come out of the same Go chan, i.e. pq.Listener.NotificationChannel(). You have to distribute them to the relevant goroutines (or what have you) yourself. (Or use something like my notifydispatcher; though I now see that it's a bit outdated.)