
Show HN: Pub/Sub with PostgreSQL under 40 lines of Python code - kissgyorgy
https://gist.github.com/kissgyorgy/beccba1291de962702ea9c237a900c79
======
SahAssar
It can be used as a more durable message queue too by following the
recommendations in
[https://www.youtube.com/watch?v=B81nQLg4RuU](https://www.youtube.com/watch?v=B81nQLg4RuU)

------
zikani_03
Nice. Reminds me of a time I was learning Rust. Did a small test to get
Node.JS and Rust to "communicate" via Postgres[0]

I am curious if this is an approach folks actually use in production, though.

[0]:
[https://gist.github.com/zikani03/e4fa4f150940dbdb03a6761fd0c...](https://gist.github.com/zikani03/e4fa4f150940dbdb03a6761fd0c41995)

------
zach_garwood
Interesting! I wonder if you could use this in a Django project with Channels,
and stream database changes over websocket to the client. I think I've found a
project for this weekend!

I must admit my DB knowledge is lacking. What is the purpose of setting the
isolation level to autocommit?

~~~
kissgyorgy

        > I wonder if you could use this in a Django project with Channels, and stream database changes over websocket to the client.I wonder if you could use this in a Django project with Channels, and stream database changes over websocket to the client.
    

That's exactly what I'm doing with this! :) But you don't even need channels
for that! The point is to simplify the stack.

    
    
        > What is the purpose of setting the isolation level to autocommit?
    

Notifications are only sent after a transaction has been committed, see:
[https://www.postgresql.org/docs/12/sql-
listen.html](https://www.postgresql.org/docs/12/sql-listen.html)

Here is an example in the psycopg2 documentation:
[https://www.psycopg.org/docs/advanced.html#asynchronous-
noti...](https://www.psycopg.org/docs/advanced.html#asynchronous-
notifications)

