Giter Club home page Giter Club logo

contractor-app's Introduction

README

Requierements

Create two simple Rails applications. Use events, carried over a message broker (eg. RabbitMQ, Kafka, Amazon SQS, etc.) for inter-app communication. It's OK to use libraries, whether it's just a client (eg. bunny) or a full-on message processing system (hutch, karafka, etc).

Each application needs to have its own, separate database.

  • Contractor app: a simple application for payment requests where a contractor can request a payment from their manager. A payment request consists of amount, currency, and text description. The contractor should be able to see all of their payment requests, whether they're pending, accepted, or rejected.

  • Manager app: a simple application that displays all payment requests submitted by the contractor. The manager can only accept or reject the payment request. The acceptance/rejection of payment request should be handled by the manager app publishing an event and the contractor app processing the event to update the status for the contractor.

Objective

I have this solution to do this:

  • Use message queue (Advanced Message Queuing Protocol) This is the solution I choose. Basically AMQP allow that a producer (our Contractor) notify our consumer (Manager) that a new payment request has been created, in a real time. Once it's created it will push this data into a dedicated queue that will be received by the consumer. Efficient, timely and single responsability compliant.

  • In this app I configure the producer.

Configuration

Main goal is to push a message in a queue when we create a new payment request. I’m going to work with RabbitMQ and the Bunny gem.

First I have to install RabbitMQ on my machine

brew install rabbitmq

then run

/usr/local/opt/rabbitmq/sbin/rabbitmq-server

and go to the admin interface http://localhost:15672/ . Password and username are « guest » .

At this point, I add the bunny gem to Gemfile

gem 'bunny'

and I instantiate a Bunny instance to start a connection, then I create a channel to fanout a queue name to this very channel.

As I want to notify the Manager each time that a payment request is created I call the publish in a create callback.

With the RabbitMQ server running in one terminal (/usr/local/opt/rabbitmq/sbin/rabbitmq-server) open a rails console and create a payment request, browse to http://localhost:15672/ and click ont the Exchange tab. You should see an Exchange named « display.payment_request ».

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.