Home

Awesome

Microservices tests

This is a repo for microservice tests using rabbitmq.

Instructions

  1. Install rabbitmq
  2. Clone this repo
  3. go into the cloned project directory
cd microservices-tests
  1. do bundle install
bundle install
  1. cd into lib, where all the exectuables are, from now on, you will execute any commands in different terminals, keeping the processes (microservices) alive.
cd lib
  1. 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.)
  2. run the keyboard client, so you can type messages, hit enter to send. Messages will be queued in rabbitmq until a consumer appears
ruby keyboard_client.rb
  1. run the gateway service which takes messages and replays them to the workers and logger through a fanout exchange.
ruby gateway.rb
  1. 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 ".".
ruby worker.rb
  1. 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.
ruby receiver.rb
  1. Run the logger, which will log the important interactions in the system. The other microservices send messages to the "logger" queue for this.
ruby logger.rb
  1. Finally, in order to not input messages manually, run:
ruby auto_client.rb

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

  1. Leave the system running and see how it behaves (basically is a message passing game)
  2. Using the keyboard client, put various messages with multiple dots "." to simulate load for the workers.
  3. Turn off services randomly and rerun them, you will see how messages are queued and processed when the microservices become available again.
  4. Enjoy!

Running each micro-service in docker container

This steps assume you have docker installed and working in your system.

Run RabbitMQ Server

  1. Create and image for rabbitmq server:
docker build -t="dockerfile/rabbitmq" github.com/dockerfile/rabbitmq
  1. Run a container from that image with:
run --name rabbitmq -d -p 5672:5672 -p 15672:15672 dockerfile/rabbitmq

Run microservices in docker

  1. Create and image for micro-services (with ruby 2.1.1 and microservices bundle) doing:
docker build -t="microservices/client" .
  1. 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