This is a template repository to serve as seed for new projects developed @somosphi. This repo uses Typescript as development language, Jest as test framework and other main packages.
Obs: This project is developed based in this repo.
$ npm install
$ npm run test
$ npm install
$ npm run build
$ npm install
$ npm run lint
If you want to run locally you will need:
- Docker
- MySQL Docker image
- RabbitMQ Docker image
- Kubernetes Cluster (optional)
- Start MySQL Docker
$ docker run --name mysql -e MYSQL_ROOT_USERNAME=my-username -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 -d mysql:5.7
- Start RabbitMQ Server Docker
$ docker run --hostname rabbitmq-host --name rabbitmq -e RABBITMQ_ERLANG_COOKIE=my-cookie -p 15672:15672 -p 5672:5672 -d rabbitmq:3.8
- Add a user to the RabbitMQ
$ docker run --rm -it rabbitmq:3.8 rabbitmqctl add_user my-username my-password
- For the user to access the RabbitMQ Management Web UI, we need to set the created user as administrator
$ docker run --rm -it rabbitmq:3.8 rabbitmqctl set_user_tags my-username administrator
- In the management console, we need to:
- Create the vHost
- Select the
Admin
tab - In the top right, select the
Virtual Hosts
option - Add the name to your virtual host -- this name will be used in the
.env
file in the propertyRABBIT_VHOST_HOME
- Click in
Add virtual host
- Select the
- Create the queues. This project is using 3 queues,
tsseed.user.create
,tsseed.user.find
andtsseed.user.notify
.- Select the
Queues
tab - Select the created virtual host
- Add the queue name in the form and select the
Lazy Mode
option, in the bottom of the form. - Click in
Add queue
- Select the
- Create the exchanges and bind the queues. In this project is used 2 exchanges,
tsseed.dx
(direct) andtsseed.fx
(fanout)- Select the
Exchanges
tab - At the form to create the exchange, select the created virtual host
- Add a name for the exchange. For
direct exchanges
add the.dx
sufix and for thefanout exchanges
add the.fx
sufix - Click in
Add exchange
- Select the
tsseed.dx
exchange to bind the direct queues- In the bind form, select
To queue
and add the name of the queue. For this direct exchange you need to bind thetsseed.user.create
andtsseed.user.find
queues
- In the bind form, select
- Go back to the exchange list and select the
tsseed.fx
exchange to bind the fanout queues- In the bind form, select
To queue
and add the name of the queue. For this fanout exchange you need to bind thetsseed.user.notify
queue and add theuser.create
routing key - Again, you need to bind the
tsseed.fx
exchange to thetsseed.user.notify
queue and add theuser.get
routing key
- In the bind form, select
- Select the
- Create the vHost
- Add the environment variables to the
.env
file - Run the MySQL migrations:
npm run migrate:up
- Run the server in development mode:
npm run dev