One part of the rewrite of all of my sites is to make dynamic content more real-time, specifically using Websockets, so that content is as close as live as it’s possible. For this I’m using the current RabbitMQ release running within a docker container with the web_stomp plugin enabled. With this I can then have a webpage connect over websockets directly into the message broker and listen for messages.
Now the problem. Most events are defined as some change within a database so I now need a method to allow a database trigger to be able to send a message to RabbitMQ without hindering performance – more so when some tables are being updated 20-40 times a second.
Fortunately PostgreSQL provides us with asynchronous notifications via the LISTEN and NOTIFY commands, so we can add a notify command to the trigger to a named queue and then have a separate process listen to that queue. All I needed to implement was an application that did the listening. Continue reading “Publishing messages to RabbitMQ from PostgreSQL”