{"id":43833996,"url":"https://github.com/robertbruno/pgnotify-rabbitmq","last_synced_at":"2026-02-06T03:34:50.811Z","repository":{"id":256666400,"uuid":"856074038","full_name":"robertbruno/pgnotify-rabbitmq","owner":"robertbruno","description":"Nodejs aplicacion to publish messages to rabbitmq via postgresql notify","archived":false,"fork":false,"pushed_at":"2024-12-07T21:09:50.000Z","size":280,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-07T21:28:01.051Z","etag":null,"topics":["docker","nodejs","notify","postgresql","rabbitmq"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertbruno.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-12T00:13:55.000Z","updated_at":"2024-12-07T21:09:54.000Z","dependencies_parsed_at":"2024-12-07T21:34:51.924Z","dependency_job_id":null,"html_url":"https://github.com/robertbruno/pgnotify-rabbitmq","commit_stats":null,"previous_names":["robertbruno/pgnotify-rabbitmq"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robertbruno/pgnotify-rabbitmq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbruno%2Fpgnotify-rabbitmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbruno%2Fpgnotify-rabbitmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbruno%2Fpgnotify-rabbitmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbruno%2Fpgnotify-rabbitmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertbruno","download_url":"https://codeload.github.com/robertbruno/pgnotify-rabbitmq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbruno%2Fpgnotify-rabbitmq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29148428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T02:39:25.012Z","status":"ssl_error","status_checked_at":"2026-02-06T02:37:22.784Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","nodejs","notify","postgresql","rabbitmq"],"created_at":"2026-02-06T03:34:50.744Z","updated_at":"2026-02-06T03:34:50.802Z","avatar_url":"https://github.com/robertbruno.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgnotify-rabbitmq\n\n🇪🇸 [Go to spanish version](docs/README_ES.md)\n\n## Introduction\nThis is a simple nodejs application that allows PostgreSQL to send messages to a RabbitMQ server using [NOTIFY](https://www.postgresql.org/docs/current/sql-notify.html).\n\nFor example, in SQL you can run the following query:\n\n```sql\nSELECT pgnotify_rabbitmq.send('rabbit', 'hola!');\n```\n\nThis application will then immediately send a message to a RabbitMQ topic with that message to a configured routing key.\nYou can then have an application listen for messages with that key and process those events immediately.\n\nSome structure and elements are expected in the database which you need to create by running the following script:\n\n* [scripts/pgnotify-rabbitmq.sql](scripts/pgnotify-rabbitmq.sql)\n\nEvery time the application starts it will execute the function `\"pgnotify_rabbitmq\".\"handle_ack\"()` with the intention of processing messages without ack.\n\n\u003e For more info see:\n\u003e * [Database Functions](docs/DBFUNCTION.md)\n\n## Build docker compose\n\n```bash\ndocker compose -f docker-compose-dev.yml  up --build\n```\n\u003e You must wait for at least 5 seconds for Rabbitmq to start.\n\n## Configuration\n\nYou need to provide a [config.yaml](src/config.yaml) file containing details about your database - a template is provided in the repository.\n\nIt consists of three sections:\n\n### databases\nThis section contains connection details to connect to your databases:\n\n```yml\ndatabases:\n    testDB:\n        enabled: true\n        host: localhost\n        port: 5432\n        database: postgres\n        user: postgres\n        password: postgres\n        ssl: false\n```\n\n\u003e You need to run the scripts [scripts/pgnotify-rabbitmq.sql](scripts/pgnotify-rabbitmq.sql) in each database.\n\u003e Here we have just one database configured called testDB which will be referred to later.\n\n### rabbit\nThis section defines details of the rabbitmq instances you want to connect to.\nIt simply consists of a name for the instance and the connection URI to connect to it.\n\n```yml\nrabbit:\n    testRabbit: amqp://guest:password@localhost\n```\n\nNote: You can put an IP address here instead of the hostname.\nIf it's an IPv6 address then wrap it within a pair of [ ].\n\n### notify\nThis section defines which databases you want to listen to for notifications.\nYou usually have one entry per database (but you are not limited to this).\n\n#### Simple messages\n\n```yml\nnotify:\n    -\n        enabled: true\n        database: testdb\n        name: rabbit\n        handlers:\n            rabbit:\n                instance: testRabbit\n                key: job.status\n```\n\nHere we are telling the application to listen for notifications sent to the 'rabbit' queue on the testdb database.\nAll messages received would be sent as-is to the testRabbit RabbitMQ instance with the routing key 'job.status'.\n\nThen from PostgreSQL you can use:\n\n```bash\necho -e \"SELECT pgnotify_rabbitmq.send('rabbit','hola');\" | docker exec -i pgnotify-rabbitmq-postgresql-1 psql -U postgres\n```\n\nto send the message.\n\n#### Set the routing key in PostgreSQL\n\nThis is a simple case, you can allow PostgreSQL to define the routing key:\n\n```yml\nnotify:\n    -\n        enabled: true\n        database: testdb\n        name: rabbit\n        json: true\n        handlers:\n            rabbit:\n                instance: testRabbit\n                routingKey: key\n                payload: body\n```\n\nHere we are telling the application to expect a JSON object from PostgreSQL with two properties.\n* \"key\" will contain the routing key to use\n* \"body\" will contain the message to send.\n\n```bash\necho \"SELECT SELECT pgnotify_rabbitmq.send('rabbit','{\\\"key\\\":\\\"key.test\\\",\\\"body\\\": \\\"My message\\\"}');\" docker exec -i pgnotify-rabbitmq-postgresql-1 psql -U postgres\n```\n\n\u003e Note: \"payload\" is optional here. If absent then the original message will be sent including the routing key etc.\n\n## FCM\n\nThis Node.js project implements an automated workflow to send push notifications via Firebase Cloud Messaging (FCM) from events generated in a PostgreSQL database.\n\nUpon receiving a NOTIFY event, the application extracts the message payload, which contains the information necessary to construct the FCM notification (e.g., title, body, device token, etc.).\n\n```sql\nSELECT pgnotify_rabbitmq.send('fcm',\n\tjson_build_object('topic', \n\t  'all-notifications',\n\t  'notification',json_build_object(\n\t  \t'title', 'Titulo',\n\t  \t'body', 'mensaje'\n\t  )\n\t)::TEXT  \n  );\n\n```\n\n## Environment\n\nYou can use environment variables to configure the service, for more info about it see:\n\n* [src/templates/config.yaml.template](src/templates/config.yaml.template)\n\n\u003e To avoid conflicts in configuration files, if you want to use environment variables you must specify USE_TEMPLATE to true\n\nOptional you can set `HANDLE_ACK` Environment variable to run `SELECT pgnotify_rabbitmq.handle_ack();` at app startup.\n\n## Running docker\n\nTo run first create a config.yaml file with your configuration then run:\n\n```bash\ndocker run -d -v $(pwd)/config.yaml:/opt/config.yaml robertbruno/pgnotify-rabbitmq:latest\n```\n\n## Monitoring with Prometheus and Grafana.\n\n[Prometheus](https://prometheus.io/) It logs real-time metrics to a time-series database built using an HTTP pull model, with flexible queries and real-time alerts.\n[Grafana](https://grafana.com/) that allows the display and formatting of metric data. Allows you to create dashboards and graphs from multiple sources, including time series databases\n\nYou can visualize this metrics in [Grafana](https://grafana.com/) with the following dashboard:\n\n* [scripts/grafana-dashboard.json](scripts/grafana-dashboard.json)\n\n\u003e For more info about metrics visit:\n\u003e\n\u003e * [Metrics docs](docs/METRICS.md)\n\n## Help\n\n* To view the change history [changelog](./src/CHANGELOG.md)\n* To view or report bug's go to [issues](https://github.com/robertbruno/pgnotify-rabbitmq/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertbruno%2Fpgnotify-rabbitmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertbruno%2Fpgnotify-rabbitmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertbruno%2Fpgnotify-rabbitmq/lists"}