Giter Site home page Giter Site logo

sub-pub-gateway's Introduction

README

A simple rails service to demonstrate consuming and publishing from a message queue.

Stack Overview

  • Ruby 2.4
  • Rails 5.1.4
  • Docker & Docker Compose
  • RabbitMq

Set up

docker-compose up --build
  • When you build and start the container, it will automatically start your Sneakers service.

  • To stop the application, go to your terminal where you are running the docker containers and press CTRL+C.

  • To stop the services, run docker-compose stop.

  • To stop the containers, run docker-compose down.

Local development

Once you have created your images, you can use docker-compose up to start the containers. Please refer to docker-compose help for all commands.

Developing a Rails application on a docker container is not so different from development in a local environment. You should be able to run all commands as you normally would, but you must prefix them with docker-compose exec ${name of container}. The containers are named as so:

  • gateway - runs Sneakers

For example, running bundle install on the Rails service looks like:

docker-compose exec gateway bundle install

See the docker-compose.yml in the root of the project for configuration.

Consuming and Publishing Messages

This service publishes messages to an AMQP server using RabbitMq. You can start this server following the directions in the message-queue repository.

This service uses Sneakers to listening to the queues and run background jobs. Starting the docker container will also start sneakers. To start it manually, you can use docker-compose exec gateway rake sneakers:run

Testing

Unit tests

docker-compose exec gateway rspec

Mountebank

Mountebank allows you to stub out responses from external dependencies. This service depends on an external service to provide the account key.

To use Mountebank, you'll need to install it:

npm install -g mountebank

To run Mountebank with the configured stubs:

 mb --configfile config/mountebank/imposters.ejs --allowInjection --logfile tmp/mb.log

Once Mountebank is running, you can go to localhost:2525 to view the Mountebank help documentation. Our stubbed service lives at localhost:9001/v1/account. To point the application to the stub, change the ACCOUNT_KEY_SERVICE environment variable.

# In the .env file, point this environment variable to your stub 

#Instead of this:
ACCOUNT_KEY_SERVICE=https://account-key-service.herokuapp.com

#Use this: 
ACCOUNT_KEY_SERVICE=http://localhost:9001

This is not an ideal set up, further work should be done to automate this.

There are a few simple stubs in available:

POST /v1/account with body:

{
  "email": "[email protected]",
  "key": "1_key"
}

or

{
  "email": "[email protected]",
  "account_key": "2_account_key"
}

will return account keys. Any other request to localhost:9001 will return back a 200 and an error message, like the real account service.

sub-pub-gateway's People

Contributors

tchen10 avatar

Watchers

James Cloos 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.