GithubHelp home page GithubHelp logo

dotran / thrift-demo Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 5.56 MB

Simple Thrift demo using Node.js and Python

License: MIT License

HTML 13.76% JavaScript 63.03% CSS 0.84% Thrift 1.46% Python 20.91%

thrift-demo's Introduction

#Thrift Demo In this repository you will find a simple example on how to make processes intercommunication using Apache Thrift to build a simple microservices architecture

##Contents This is a very simple Task application.
Simple architecture
Clients connect directly with the Web Server which deals with authentication, data validation, etc.

The Web Server connects with the Tasks service using Thrift to fetch and submit data

Note: Please refer to Routes for the basic Routing of the Web Server

##Prerequisites To successfully run this demo please install the following dependencies:

###Thrift installation tip For a simpler installation process of Thrift in a OSX environment the following Homebrew formula can be used:

brew install thrift

###Install After installing all the dependencies execute the following in a terminal application/emulator: (replace /path/to/demo with the actual folder the repo was cloned)

cd /path/to/demo

Install all node.js server dependencies

cd server && npm install

Create virtual environment for python with $ENV name and activate it

cd ../tasks 
virtualenv $ENV
. $ENV/bin/activate

Install Python dependencies

pip install -r requirements.txt

Install Angular.js dependencies
In another terminal window, assuming you are in the base folder of the project

cd client && npm install && bower install

###Configuration Please refer to the config.json file to change the configuration of your services

If the webserver configuration is changed please also change the client/config.json file accordingly

###Run ####MongoDB: Make sure you have an instance of MongoDB running and that it is accessible

To start MongoDB using a $MONGO_FOLDER as Database file folder

mongod --dbpath $MONGO_FOLDER

####Webserver: From the base folder type the following:

node server/.

####Tasks Service: Activate the virtual environment and from the base folder type the following:

python newserver.py

This will run the python Thrift server using thriftpy library.

####Client App
For all the necessary processing and automated tasks Gulp is being used.

From the terminal navigate to the client folder

cd client

From the terminal type the following to start a webserver for development. A browser window/tab should open automatically

gulp

After updating the application use the following command to bundle and update the client code from the server/client folder

gulp deploy

Note: After deploying you should be able to access the application using the same address that the webserver is running in browser e.g. http://localhost:3001/

##Thrift files ###demo.thrift In this file we are importing the other two thrift files and will generate the Thrift classes for Webserver

###tasks.thrift This file describes the Tasks service and struct

###Generating the thrift classes If you want to change the thrift files and update the services accordinly follow the steps below: ####Webserver From the base folder in the terminal application:

  1. Build the new files. This command will generate the classes and services for Node.js in a gen-nodejs folder
thrift -r --gen js:node demo.thrift
  1. Remove the current generated files from the server folder server/server/gen-nodejs/
rm -r server/server/gen-nodejs
  1. Move the newly generated files to the server/server folder
mv gen-nodejs server/server

####Tasks service As the tasks service will only deal with Tasks we can build only the necessary classes for it. From the base folder in the terminal application:

  1. Build the new files. This command will generate the classes and services for Python in a gen-py folder
thrift -r --gen py tasks.thrift
  1. Remove the current generated files from the server folder tasks/gen-py/
rm -r tasks/gen-py
  1. Move the newly generated files to the tasks folder
mv gen-py tasks


##Client (client folder)

  • Angular.js client application
  • Use gulp to start the development server
  • Use gulp deploy to update the client app inside the server/client folder

##Webserver (server folder)

  • Node.js webserver using Express 4.x
  • Serves the client interface
  • Deals with authentication and authorization
  • Works as a proxy between the clients and the other services

##Tasks Service (tasks folder)

  • Python Thrift server
  • Manages changes to Tasks data

##TODO

  • Create web user interface
  • Publish Services using docker and loadbalancing
  • Create unit tests for each service
  • Add Report microservice
  • Add REST microservice

##License The MIT License (MIT)

Copyright (c) 2013-2016 Fractal [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

##Notes This demo was built and tested using the following environment:
MacBook Pro (Retina, 13-inch, Late 2013)
Processor: 2.4 GHz Intel Core i5
Memory: 8 GB 1600 MHz DDR3
OS: OSX 10.10.5

thrift-demo's People

Contributors

danielfbm avatar

Watchers

James Cloos avatar Do Tran 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.