-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add postgres transport #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 0.x
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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