Code Monkey home page Code Monkey logo

postgresql-to-amqp's Introduction

โš ๏ธ Discontinued

@subzerocloud took inspiration from this project and built pg-amqp-bridge which now has more options, use it instead ๐Ÿ‘


๐Ÿš‡ PostgreSQL to AMQP gateway

Forward PostgreSQL pg_notify notifications to an AMQP queue.

Cargo version Crates.io Crates.io Docker Automated build Docker Pulls Docker Stars Slack

โ›ด Cargo

cargo install postgresql-to-amqp

๐Ÿณ Docker

docker run --rm -it \
-e POSTGRESQL_URI=postgresql://username:[email protected]:port/database \
-e POSTGRESQL_CHANNEL=foo \
-e AMQP_URI=amqp://127.0.0.1:5672/ \
-e AMQP_QUEUE_NAME=queueName fgribreau/postgresql-to-amqp

โš™ Configuration

Configuration is done through environment variables:

  • POSTGRESQL_URI: e.g. postgresql://username:[email protected]:port/database
  • POSTGRESQL_CHANNEL: e.g. foo
  • AMQP_URI: e.g. amqp://127.0.0.1:5672/
  • AMQP_QUEUE_NAME: e.g. queueName

๐ŸŽฉ Usage

Start the forwarder:

POSTGRESQL_URI="postgresql://username:[email protected]:port/database" POSTGRESQL_CHANNEL="foo" AMQP_URI="amqp://127.0.0.1:5672/" AMQP_QUEUE_NAME="queueName" postgresql-to-amqp

Execute in psql:

SELECT pg_notify('foo', 'payload');

The forwarder will log and forward the notification to the amqp queue:

Forwarding Notification { process_id: 31694, channel: "foo", payload: "payload" } to queue "queueName"

๐Ÿ‘ Philosophy

  • Low memory consumption (1,9Mo)
  • Single binary
  • No dependency
  • Predictable performance

๐Ÿ”ซ Todo

I will happily accept PRs for this:

  • AMQP connection string (AMQP authentication support) ๐Ÿ‘ป
  • Support JSON message
  • Publish to exchange
  • Add original channel as message property
  • Add postgresql-to-amqp version as message property
  • Let environment variables specify additional message properties
  • Handle AMQP disconnection/reconnection
  • Handle PostgreSQL disconnection/reconnection
  • Health check route
  • Metric route
  • Docker support
  • Kubernetes support ๐Ÿ˜
  • Make a first major release with tests โ˜๏ธ

Related work

  • pgsql-listen-exchange - RabbitMQ Exchange that publishes messages received from PostgreSQL Notifications

postgresql-to-amqp's People

Contributors

fgribreau avatar keruspe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

keruspe

postgresql-to-amqp's Issues

A few ideas (if you want to consider)

I see this as a "bridge" between the two components, so with this idea in mind, why not have the convention that the PG channel is equal to the RMQ entity, where entity is either an exchange or a queue. This is also probably the way users will want to set up things anyway, in order to make it obvious where the PG event will end up in RabbitMQ.

I am not sure if this component should take on the creation of the queue/exchange since this will complicate the code and the config interface, maybe it should just error out (or try to reconnect again) if the entity is not yet created in Rabbit.

Another idea to consider is that you probably want to be able to bridge multiple channels at the same time (each handled by a separate thread)

With this ideas/features in place, the config interface is very simple yet very flexible/powerful

docker run --rm -it \
-e POSTGRESQL_URI=postgresql://username:[email protected]:port/database \
-e AMQP_HOST_PORT=127.0.0.1:5672 \
-e BRIDGE_CHANNELS="foo:queue,bar:exchange" \
fgribreau/postgresql-to-amqp

What do you think?

AMQP_HOST_PORT format issue

Hi. I'm experiencing an issue with setting AMQP_HOST_PORT to FQDN instead of IP.

$ docker logs rabbitmqexample_postgresql-to-amqp_1
    Finished release [optimized] target(s) in 0.6 secs
     Running `target/release/postgresql-to-amqp`
thread 'main' panicked at 'amqp_host_port should be in format '127.0.0.1:5672': AddrParseError(())', /checkout/src/libcore/result.rs:859
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Here is sample docker-compose.yml file to reproduce the issue. Save it and run docker-compose up and you will see the same error message as above.

version: '2'
services:
  postgresql:
    image: postgres:9.5.3
    ports:
      - "5432"
    depends_on:
      - rabbitmq
    environment:
      - POSTGRES_PASSWORD=password
      - POSTGRES_USER=postgres
      - POSTGRES_DATABASE=test
  rabbitmq:
    image: rabbitmq:3.6.9-alpine
    hostname: test-rabbitmq
    mem_limit: 256m
    ports:
      - "5672"
  postgresql-to-amqp:
    image: fgribreau/postgresql-to-amqp:0.1.3
    environment:
      - POSTGRESQL_URI="postgresql://postgres:password@postgresql:5432/test"
      - POSTGRESQL_CHANNEL="mychannel"
      - AMQP_HOST_PORT="rabbitmq:5672"
      - AMQP_QUEUE_NAME="myqueue"
    depends_on:
      - rabbitmq
      - postgresql

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.