Skip to content

Read a specific payload message from a Message Queue System and store it into the database system

License

Notifications You must be signed in to change notification settings

christiangda/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 consumers could be different from the numbers of 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).

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

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