Coder Social home page Coder Social logo

ashniu123 / thrift-graphql-demo Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 482 KB

Thrift servers in Golang, and Nodejs Thrift client exposed using Apollo GraphQL. Includes K8s and Istio YAMLs.

Home Page: https://www.nisheetsinvhal.com/microservices-thrift-nodejs-golang-graphql/

Shell 4.62% Dockerfile 4.80% JavaScript 51.11% Thrift 6.14% Go 33.32%
apache-thrift golang nodejs graphql apollo-graphql docker docker-compose kubernetes

thrift-graphql-demo's Introduction

Thrift GraphQL Demo

This repo is in my blog post.

This repo has 3 services

  • service-gql
    • Written in Nodejs
    • Uses Thrift clients to communicate to other services
    • Apollo GraphQL server
  • service-post
    • Written in Golang
    • Thrift server for Posts data
  • service-user
    • Written in Golang
    • Thrift server for User data

Each service has a /deployments folder which contains a Dockerfile to build the image.

Get started

Kubernetes

In the root of the directory and kubectl configured for the kubernetes cluster

$ kubectl apply -R -f k8s/

Docker Compose

In the root of the directory and having docker-compose installed

$ docker-compose up

Native

In each of the service-post and service-user folder

$ go mod download
$ go run cmd/thrift/main.go -addr :<port>

By default the port is 9090 so be sure to change them for any one service

In the service-gql folder

$ npm install

Create .env file in the folder and add the following lines

GRAPHQL_PORT=3000
SERVICE_USER_HOST=localhost
SERVICE_USER_PORT=9090
SERVICE_POST_HOST=localhost
SERVICE_POST_PORT=9091

Or, alternatively - set the values as environment variables

And finally

$ npm start

Check

$ curl -H 'Content-Type: application/json' -X POST -d '{"query": "query { ping { message } postPing { message } userPing { message  } }"}' http://localhost:3000/graphql
{"data":{"ping":{"message":"ping"},"postPing":{"message":"ping"},"userPing":{"message":"ping"}}}

You can see the logs accordingly for each service

Modifying Thrift

You can modify the .thrift files in any service-{user,post} and be sure to copy them over to service-gql. Then simply run the following service in the folder.

$ ./build/thrift-gen.sh

Don't forget to implement the changes!

Don't forget to change the schema!

Future

  • Further implementation
    • CRUD for service-user
    • CRUD for service-post
    • Healthchecks for all services
  • Istio
    • Make another image with _version as 2 (Enables Traffic Shifting, etc)
    • Metrics

thrift-graphql-demo's People

Contributors

ashniu123 avatar dependabot[bot] avatar

Stargazers

 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.