This is a repo for microservice tests using rabbitmq.
- Install rabbitmq
- Clone this repo
- go into the cloned project directory
- do bundle install
- cd into lib, where all the exectuables are, from now on, you will execute any commands in different terminals, keeping the processes (microservices) alive.
- edit configuration.rb to set the connection url to the rabbitmq server if necessary (just in case you are using non-default values for the ports, user, password, etc.)
- run the keyboard client, so you can type messages, hit enter to send. Messages will be queued in rabbitmq until a consumer appears
- run the gateway service which takes messages and replays them to the workers and logger through a fanout exchange.
- run ANY number of workers. In order to control how much time workers perform a task, just type dots "." in the message you send using the keyboard client, example: "Hello!...." will take 4 seconds to process, because it has 4 dots ".".
- Run the receiver, which is the last stop for processed messages. Processed messages are the ones that have any digits in the message body, complying to the pattern /\d/. Processed messages are upcased.
- Run the logger, which will log the important interactions in the system. The other microservices send messages to the "logger" queue for this.
- Finally, in order to not input messages manually, run:
This will basically send a message to "queue_a" every second so you can see how the overall system works by looking a the various console outputs for each of the microservices.
Interesting thing you can do now
- Leave the system running and see how it behaves (basically is a message passing game)
- Using the keyboard client, put various messages with multiple dots "." to simulate load for the workers.
- Turn off services randomly and rerun them, you will see how messages are queued and processed when the microservices become available again.
Running each micro-service in docker container
This steps assume you have docker installed and working in your system.
Run RabbitMQ Server
- Create and image for rabbitmq server:
docker build -t="dockerfile/rabbitmq" github.com/dockerfile/rabbitmq
- Run a container from that image with:
run --name rabbitmq -d -p 5672:5672 -p 15672:15672 dockerfile/rabbitmq
Run microservices in docker
- Create and image for micro-services (with ruby 2.1.1 and microservices bundle) doing:
docker build -t="microservices/client" .
- Run each microservice in a terminal as in steps 7 to 11 of the Instructions part, replacing microservice.rb with the corresponding ruby file.
docker run --link rabbitmq:amq -t -i microservices/client ruby lib/microservice.rb