Skip to content

robertbruno/mq-to-db

 
 

Repository files navigation

mq-to-db

This is a Golang (go) program to read from a Message Queue System and Store into Database using concurrency as you can see into the image below

mq-to-db

Consumers supported

Storage supported

Characteristics

  • The number of queue consumers could be different from the numbers of storage workers
  • The process (job) of consume one message from queue and store into the database is synchronous because every message needs to be acknowledge (confirm as storage).
  • Prometheus metrics for consumers, storage workers, go statistics and database.
  • Grafana dashboard for prometheus metrics
  • Dockerfile multi-stage build
  • Makefile to facilitate the project builds
  • docker-compose file and configuration to test all elements

How to execute

source code

git clone https://github.com/christiangda/mq-to-db.git
cd mq-to-db/
go run -race  ./cmd/mq-to-db/main.go --help

# and then
go run -race  ./cmd/mq-to-db/main.go --configFile config-sample.yaml

NOTE: the parameter -raceis to check race conditions because we are using Go Concurrency

binary

./mq-to-db --help

RabbitMQ

docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management

NOTE:

PostgreSQL

docker run --rm  --name postgresql -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres

# logs
docker logs postgresql -f

# remember to  stop and remove (--rm in docker run do it for you)
docker stop postgresql

mq-to-db

go run -race  ./cmd/mq-to-db/main.go --configFile config-sample.yaml

o

make
./mq-to-db --configFile config-sample.yaml

docker-compose

Up

docker-compose up --build

Down

docker-compose down -v

Links

Logs

docker-compose logs mq-to-db-01
docker-compose logs mq-to-db-02

How to build

Manually

go build \
    -o mq-to-db \
    -ldflags "-X github.com/christiangda/mq-to-db/internal/version.Version=$(git rev-parse --abbrev-ref HEAD) -X github.com/christiangda/mq-to-db/internal/version.Revision=$(git rev-parse HEAD) -X github.com/christiangda/mq-to-db/internal/version.Branch=$(git rev-parse --abbrev-ref HEAD) -X github.com/christiangda/mq-to-db/internal/version.BuildUser=\"$(git config --get user.name | tr -d '\040\011\012\015\n')\" -X github.com/christiangda/mq-to-db/internal/version.BuildDate=$(date +'%Y-%m-%dT%H:%M:%S')" \
    ./cmd/mq-to-db/main.go

Automatic

make

NOTES related to make

    1. This create a linux binary (64bits) and also Docker Image (linux 64 bit)
    1. Check the Makefile to see the make targets

Internal References

External References

Free books

Blogs

Databases

Project Layout

Interfaces

Context

YAML|JSON to Struts

Config Files, Flags, Env Vars

RabbitMQ

Logs

### Metrics

### Tests

Variable Injection

Iterators

Concurrency

Workers Pool

About

Read from Message Queue System and Store into Database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 93.8%
  • Makefile 4.3%
  • Dockerfile 1.9%