Skip to content

robertbruno/pgnotify-emitter

Repository files navigation

pgnotify-emitter

🇪🇸 Go to spanish version

Introduction

This is a simple nodejs application that allows PostgreSQL to send messages to a emitter server using NOTIFY.

For example, in SQL you can run the following query:

SELECT pgnotify_emitter.keygen('emitter-channel-demo1','{
    "channel": "test/"
}');

SELECT pgnotify_emitter.publish('emitter-channel-demo1','{
    "channel": "test/1",
    "message": "xxxxxxx"
}');

This application will then immediately send a message to a emitter channel. You can then have an application listen for messages with that key and process those events immediately.

Some structure and elements are expected in the database which you need to create by running the following script:

Every time the application starts it will execute the function "notify_emitter"."handle_ack"() with the intention of processing messages without ack.

For more info see:

Development

  • Clone Ejecutar el clone del repositorio en su ambiente local:
# clon del repositorio
git clone https://github.com/robertbruno/pgnotify-emitter.git \
    ~/workspace/workspace-node/pgnotify-emitter/

# Ingresamos al repo
cd  ~/workspace/workspace-node/pgnotify-emitter/src
  • npm Dependencias npm
npm i --unsafe-perm
  • docker-compose: Puede ejecutar todos los servicios necesarios usando docker-compose, este proyecto posee un script npm que le permite la ejecución sin problemas de estos servicios:
# Builds, (re)creates, starts containers.
npm run docker:compose:up

# Stops and removes containers, networks, volumes, and images created by up
npm run docker:compose:down

Para mayor información sobre docker compose visite:

Configuration

You need to provide a config.yaml file containing details about your database - a template is provided in the repository.

It consists of three sections:

databases

This section contains connection details to connect to your databases:

databases:
    testDB:
        enabled: true
        host: localhost
        port: 5432
        database: postgres
        user: postgres
        password: postgres
        ssl: false

You need to run the scripts scripts/notify-emitter.sql in each database. Here we have just one database configured called testDB which will be referred to later.

emitter

This section defines details of the emitter instances you want to connect to. It simply consists of a name for the instance and the connection URI to connect to it.

# emitter servers configuration
emitters:
    local:
        enabled: true
        host: localhost
        port: 8080
        secure: false

Environment

You can use environment variables to configure the service, for more info about it see:

To avoid conflicts in configuration files, if you want to use environment variables you must specify USE_TEMPLATE to true

Optional you can set HANDLE_ACK environment variable in tue to run SELECT pgnotify_emitter.handle_ack(); on app startup.

Running docker

To run first create a config.yaml file with your configuration then run:

docker run -d -v $(pwd)/config.yaml:/opt/config.yaml robertbruno/pgnotify-emitter:latest

Monitoring with Prometheus and Grafana.

Prometheus It logs real-time metrics to a time-series database built using an HTTP pull model, with flexible queries and real-time alerts. Grafana that allows the display and formatting of metric data. Allows you to create dashboards and graphs from multiple sources, including time series databases

You can visualize this metrics in Grafana with the following dashboard:

For more info about metrics visit:

Help

  • To view the change history changelog
  • To view or report bug's go to issues

About

Nodejs aplicacion to publish messages to emitter server via postgresql notify

Topics

Resources

Stars

Watchers

Forks