Git Product home page Git Product logo

microservice-tests-01's Introduction

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

microservice-tests-01's People

Contributors

gato-omega avatar jpamaya avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.