mercadona / postoffice

A dispatching service implemented in Elixir. Communicate services or sent api calls to yourself to process anything later
Apache License 2.0
23 stars 7 forks source link
elixir pubsub

Postoffice

CircleCI Coverage Status


What's Postoffice?

We can think about Postoffice as a real post office. You send messages to a topic and publishers send them to anyone interested in this topic. In case the receiver is not available, Postoffice will try to deliver the message later. Postoffice uses a pub/sub approach, so instead of handling receiver's addresses it uses topics, to which receivers must subscribe through Publishers. A publisher is isolated from others and it handles itself its own pending messages.

Motivation

This project started as a solution to buffer messages in case some apps are deployed on-premise and could suffer connectivity issues. Then it evolved to also offer a pub/sub mechanism.

What's not Postoffice?

This is not designed to be realtime. Postoffice uses GenStage to process pending messages, creating a process tree for each Publisher. It looks like an ETL, and it's refreshed every 10 seconds.

Features

API

We expose an API to enable projects to create the structure they need to work: topics, publishers and messages. For both topics and publishers, if the resource already exist we return 409 Conflict. In case that another validation error happened, we return 400 bad request

Topics

Here we have a sample request to create a topic. All fields are required

POST /api/topics
{
  "name": "example-topic",
  "origin_host": sender_service.com
}

Attributes:

Publishers

Publishers creation example. The only non required field is from_now

POST /api/publishers
{
  "active": True,
  "topic": "example-topic",
  "target": "http://myservice.com/examples",
  "type": "http/pubsub",
  "from_now": True
}

Attributes:

Messages

Message creation example. All fields are required

POST /api/messages
{
  "topic": topic,
  "payload": {},
  "attributes": {}
}

Attributes:

How to install it locally

To start your Phoenix server:

How to install it locally with docker

To start postoffice bundle with docker:

[1] While make env-start you can execute make view-logs in other terminal to show what is happening

Environment variables

Clustering

Postoffice has been developed to be used forming a cluster. We use libcluster under the hood to create the cluster. You can take a look at its documentation in case you want to tune settings.

What's next?

Some desired features have been delayed until the first release: