This repository is a proof of concept (PoC) in which I implement the transactional outbox pattern
with the hexagonal pattern to have the service/sender
and
the message relay
in the same code base to avoid having different projects sharing databases.
(Also this project can be used as a template)
As the diagram shows, this project is compiled in two parts:
outbox-http
It is the binary in charge of manage the http requests related with purchases (service/sender)outbox-relay
It is the binary in charge of read and send the messages (message relay)
I decided to follow the Go project layout standard.
I built the package tree following the concepts of the hexagonal architecture pattern.
.
├── cmd
├── internal
│ ├── app
│ │ ├── business (Use cases, rules, data models and ports)
│ │ ├── input (Everything related to "drive" adapters)
│ │ └── output (Everything related to "driven" adapters)
│ └── container (DI container)
└── pkg (Public and global code, potencially libraries)
According to the theory of hexagonal architecture, it is possible to have n adapters for different external signals (http, gRPC, command line).
So I decided to compile a binary to handle each signal.
The database schema is described by the .sql
files in the sql directory.
To build the database run the following command.
make database
See the required environment variables
go install -tags http github.com/yael-castro/outbox/cmd/outbox-http
go install -tags relay github.com/yael-castro/outbox/cmd/outbox-relay
All compiled binaries will put in the build
directory
make http
./build/outbox-http
make relay
./build/outbox-relay