Skip to content
[STANDALONE, DOCKER] - When AMQP connection limits of a RabbitMQ broker exceed quickly, this service is willing to help by accepting messages on behalf via POST and funnel them through fewer persistent AMQP connections.
Go Makefile Dockerfile Shell Ruby
Branch: master
Clone or download
Daniel T. Gorski
Daniel T. Gorski -
Latest commit a2a8b7a Oct 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd
internal
tool - Oct 8, 2019
.dockerignore - Oct 8, 2019
.gitignore
.travis.yml - Oct 8, 2019
Dockerfile - Oct 8, 2019
Dockerfile.builder
LICENSE - Oct 8, 2019
Makefile - Oct 8, 2019
README.md
docker.env-dist - Oct 8, 2019
go.mod - Oct 8, 2019
go.sum
revive.toml - Oct 8, 2019

README.md

Build Status Coverage Status

rabbitpublishd

HTTP to RabbitMQ publisher.

 ┌─────────────┐                                                 ┌─────────────┐
 │ HTTP client ├─ stateless ─> ╔════════════════╗                │ AMQP broker │
 └─────────────┘               ║                ╟─ persistent ─> │ [RabbitMQ]  │
 ┌─────────────┐               ║ rabbitpublishd ║                └──────┬──────┘
 │ HTTP client ├─ stateless ─> ║                ║                       │
 └─────────────┘               ║     [this]     ║                ┌──────┴──────┐
 ┌─────────────┐               ║                ╟─ persistent ─> │ AMQP broker │
 │ HTTP client ├─ stateless ─> ╚════════════════╝                │ [RabbitMQ]  │
 └─────────────┘                                                 └──────┬──────┘
       .                                                                .
       .                                                                .
       .                                                                .

Too many short-living clients trying to connect and publish to RabbitMQ may exceed the AMQP connection limits of the broker quickly. rabbitpublishd is willing to help by accepting messages on behalf via POST and funnel them through fewer persistent AMQP connections.

Usage

$ git clone https://github.com/dtgorski/rabbitpublishd.git
$ cd rabbitpublishd
$ make docker
$ cp docker.env-dist docker.env

Modify the docker.env file according to your needs:

Key Purpose
TOKEN A HTTP client must pass this token in X-Access-Token header in order to be successfully able to access this endpoint. A sane token must contain at least 16 characters and should not be guessable.
BROKER One or more RabbitMQ AMQP endpoints separated by comma. You may specify identical URLs multiple times, especially when you run out of channels, but usually you want to connect to different RabbitMQ cluster nodes.
EXCHANGE The name of the exchange to publish to. The EXCHANGE value may remain empty, when the ROUTING key denotes a queue as destination. For more information about message exchanges, please refer to the RabbitMQ documentation.
ROUTING A routing key - or a queue name, to route messages to. For more information about message routing, please refer to the RabbitMQ documentation.
REPLYTO The name of the callback queue for the consumer to reply to. This value is optional and may remain empty.

Save the file and start the container:

$ docker run -d --env-file ./docker.env -p8080:8080 rabbitpublishd

Test publishing a message e.g. with curl:

curl -XPOST http://localhost:8080/publish \
  -H 'X-Access-Token: <YOUR_TOKEN>'       \
  -H 'Content-Type: application/json'     \
  -d '{"foo":"bar"}' 

This service will not verify the integrity of the POSTed payload, like e.g. JSON validity. The payload is passed directly and unchanged - even multipart - to the RabbitMQ broker. The maximal message size is limited to 32 KiB.

Response status codes

Response Reason
204 No Content Everything is OK, the broker confirmed the reception of the message.
403 Forbidden X-Access-Token is missing in the request or the token value does not match.
404 Not Found The requested resource has not been found, wrong path?
405 Method Not Allowed Only POST requests are handled by the service.
413 Request Entity Too Large The size of the POST body hit the maximum limit.
415 Unsupported Media Type The request provided an invalid MIME content type.
422 Unprocessable Entity Communication problems with RabbitMQ in the background.

Runtime metrics

A running rabbitpublishd service exposes the expvar runtime monitoring information under /debug/vars. Access to this resource should happen with GET, successful hits on this resource path are not logged.

Logging

The service emits an access log to stdout and errors to stderr.

@dev

Try make:

$ make

 make help       Displays this list
 make dump       Displays declared Makefile variables
 make clean      Removes build/test artifacts
 make build      Builds static executable binaries
 make test       Runs integrity test with -race
 make docker     Creates image: make docker tag=<TAG[:BUILD_KEY]>
 make format     Formats (changes) Go source files
 make sniff      Format check & linter (void on success)

License

MIT - © dtg [at] lengo [dot] org

You can’t perform that action at this time.