Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MQTT Client subscribe to PostgreSQL DB Changes

I have a PostgreSQL DB that updates periodically, and want to publish the latest changes to a mosquitto broker. What is the most elegant way to do this approach ?

like image 816
Sadik Hasan Avatar asked Sep 11 '26 11:09

Sadik Hasan


1 Answers

Ok this idea is interesting i am using PostgreSQL 9.5 and in the console if i type CREATE LANGUAGE plpythonu; the python language is available. But how i can receive the whole database and the periodically changes of the database into my Broker.

CREATE FUNCTION publishChanges ()
  RETURNS integer
AS $$
  import paho.mqtt.client as mqtt
  import paho.mqtt.publish as publish
  #client = mqtt.Client()
  #client.connect("localhost", 1883, 60)

  publish.single("test/data", SELECT * from table ,hostname="127.0.0.1")

  #client.loop_forever()
$$ LANGUAGE plpythonu;
like image 128
Sadik Hasan Avatar answered Sep 13 '26 02:09

Sadik Hasan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!