Conversation
8bf1d2b to
c3523c2
Compare
|
Another approach here could be to have a |
| this.#subscriber.on('end', () => { | ||
| debug('subscriber connection ended') | ||
| this.#subscriberConnected = false | ||
| // Attempt to reconnect | ||
| this.#subscriber | ||
| .connect() | ||
| .then(() => { |
There was a problem hiding this comment.
You'll probably want to use some form of exponential backoff with randomised jitter to ensure safe reconnection during outages.
You probably also want to check here if you should reconnect, e.g., disconnect may emit an end event (I can't recall if it does)
| await this.#subscriber.query(`LISTEN ${escapedChannel}`) | ||
| } | ||
|
|
||
| onReconnect(callback: () => void): void { |
There was a problem hiding this comment.
You'll also want to track that you are in fact actually reconnecting, and in that case, block ensureConnected on that reconnection promise, otherwise it's possible that a temporary disconnect can trigger a double connection.
hi @ThisIsMissEm thanks for your review |
Implements a new transport backend for PostgreSQL using NOTIFY/LISTEN for pub/sub messaging
Implementation
Transport:
PostgresTransportescapeIdentifier()andescapeLiteral()from pg for SQL safetyDependencies:
pgas optional peer dependency,@testcontainers/postgresqlfor testsUsage
Notes
Warning
I think it's only compatible with v14+ postgres