Skip to content
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

LISTEN/NOTIFY Is it possible? #27

Open
txbm opened this issue Oct 4, 2016 · 2 comments
Open

LISTEN/NOTIFY Is it possible? #27

txbm opened this issue Oct 4, 2016 · 2 comments
Assignees

Comments

@txbm
Copy link

txbm commented Oct 4, 2016

Is it possible to execute! a LISTEN statement and have the callback be invoked asynchronously for new values? Or anyway of doing this?

Nice work by the way. Works well for everything else I'm doing.

@alaisi
Copy link
Owner

alaisi commented Oct 20, 2016

Hi,

short answer: not yet, long answer: yes and no.

The underlying Java library supports LISTEN, and you can access it directly as the object returned by open-db is a Listenable.

However, this hasn't added to the clojure driver (or documented) as the LISTEN/NOTIFY support is not yet reliable in the sense that if the connection is broken/closed due to e.g. a network glitch, the listening stops. The listener has no reliable way of detecting this and resubscribing so the events stop flowing.

The current horrible workaround would be to create a pool with a single connection only, checking out that connection, adding a listener and then running healthchecks on the connection.

@alaisi alaisi self-assigned this Oct 20, 2016
@txbm
Copy link
Author

txbm commented Oct 31, 2016

@alaisi Haha, I ended up discovering all that the hard way :) Ended up creating a dedicated LISTEN service that uses psycopg2 as it has more mature support for this feature and it replicates the PG mutations onto a Kafka topic which my Clojure service then consumes from. A bit of a wild work-around for the moment but my attempts to create a reliable LISTEN/NOTIFY setup using Java/Clojure proved fruitless. Anyway, appreciate you taking the time to confirm your experience and I look forward to future support. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants