GithubHelp home page GithubHelp logo

brajput24 / gr8tparties Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cesartl/gr8tparties

0.0 2.0 0.0 100 KB

Simple project to showcase a micro service architecture using Spring Boot, Netflix OSS, Docker and Kubernetes

Shell 5.93% Java 94.07%

gr8tparties's Introduction

gr8tparties

Simple project to showcase a micro service architecture using Spring Boot, Netflix OSS, Docker and Kubernetes

What is it?

This is a simple application using a micro-services architecture. It aims at demonstrating how popular frameworks and technologies can work together to easily achieve a scalable and reliable micro-services architecture.

What is it made of?

This project makes use of the following technologies:

  • Spring Boot to bootstrap each micro-service
  • Netflix Zuul to provide a Edge Service proxy that routes calls to the appropriate micro-service
  • Netflix Ribbon to load balance requests
  • Netflix Feign to create easily flexible and testable REST clients
  • Netflix hystrix to provide failsafe architecture with fallbacks
  • Spring Configuration to easily switch between local and cloud deployments
  • Kubeflix Ribbon Discovery to provide service discovery and load balancer in a Kubernetes ClusterFirst
  • Protocol Buffer to define message structure for communicating with the micro-services
  • Docker to containerize each micro-service
  • Kubernetes to deploy and scale the Docker images

How to throw a great party

Best parties are attended by friends and that's what this application aims to do!. The application is made of 3 services:

  • edge-service: The only service exposed to the outside world. Its role is to route requests to the downstream services
  • friend-service: This service is responsible for creating users and managing friendships
  • party-service: This service allows you to create parties and see if your friends are attending a given party (by talking to the friend-service)

Pre-requisite

Java

This project require Java 10 to build - that's a good excuse to upgrade ;)

Pre-requisite: Install your Kubernetes Cluster

If you don't have a running Kubernetes (k8s) cluster, you can install one by following the Kubernetes documentation.

If you have an AWS account do use kops it rocks!

How to use?

Step 1: Run locally

Spring configuration provides the concept of profiles to easily group and segregate configurations between environments. The default profile is the local profile. It expects the service to run on the following ports:

  • friend-service: port 8080
  • party-service: port 8081

Let's start the services:

cd friend-service
mvn clean spring-boot:run -DPORT=8080
cd party-service
mvn clean spring-boot:run -DPORT=8081
cd edge-service
mvn clean spring-boot:run -DPORT=9999

Now the services have started you can hit the API using your favourite REST client (mine is POSTMAN!)

create a few friends

curl -d "@json/mark.json" -H "Content-Type: application/json" -H "Accept: application/json" -X POST localhost:9999/friend-service/friends
{
  "id": "5b0d768008ad890007202e6f",
  "username": "mark",
  "firstName": "Mark",
  "lastName": "Knopfler"
}
curl -d "@json/tracy.json" -H "Content-Type: application/json" -H "Accept: application/json" -X POST localhost:9999/friend-service/friends
{
  "id": "5b0d768008ad890007202e70",
  "username": "tracy",
  "firstName": "Tracy",
  "lastName": "Chapman"
}
curl -d "@json/eric.json" -H "Content-Type: application/json" -H "Accept: application/json" -X POST localhost:9999/friend-service/friends
{
  "id": "5b0d768008ad890007202e71",
  "username": "eric",
  "firstName": "Eric",
  "lastName": "Clapton"
}

Then setup some friendships (mark <-> tracy and mark <-> eric):

curl -H "Accept: application/json" -X GET localhost:9999/friend-service/friends/befriend/mark/tracy
curl -H "Accept: application/json" -X GET localhost:9999/friend-service/friends/befriend/mark/eric

Now let's great a party:

curl -H "Accept: application/json" -X POST localhost:9999/party-service/
{
  "id": "5b0d7937fc938500072fb3a5"
}

Let's everyone attend

curl -H "Accept: application/json" -X GET localhost:9999/party-service/attend/5b0d7937fc938500072fb3a5/mark
curl -H "Accept: application/json" -X GET localhost:9999/party-service/attend/5b0d7937fc938500072fb3a5/tracy
curl -H "Accept: application/json" -X GET localhost:9999/party-service/attend/5b0d7937fc938500072fb3a5/eric

Let's see if user mark should go to this party?

curl -H "Accept: application/json" -X GET localhost:9999/party-service/myParties/eric
{
    "parties": [
        {
            "id": "5b0d7937fc938500072fb3a5",
            "invited": [
                {
                    "username": "mark"
                },
                {
                    "username": "tracy"
                },
                {
                    "username": "eric"
                }
            ],
            "friends": [
                {
                    "id": "5b0d768008ad890007202e6f",
                    "username": "mark",
                    "firstName": "Mark",
                    "lastName": "Knopfler"
                }
            ]
        }
    ]
}

If the friend service is not available or becomes too slow, the request gracefully fallbacks to a reduced answer.

For example if you stop the friend-service process the response will be:

{
    "parties": [
        {
            "id": "5b0d7937fc938500072fb3a5",
            "invited": [
                {
                    "username": "mark"
                },
                {
                    "username": "tracy"
                },
                {
                    "username": "eric"
                }
            ]
        }
    ]
}

Step 2: Build with Docker

Each project has a Dockerfile which will build a Docker image. The docker-build.sh script will build the project using Maven and then run the docker build command.

cd friend-service
./docker-build.sh
cd party-service
./docker-build.sh
cd edge-service
./docker-build.sh

The Dockerfiles use Jlink to create a small JDK that can be used at runtime.

If you want you can run all docker images locally by exposing the same ports as Step 1.

Step 3: Push your docker images

If you don't have an account on Docker Hub create one.

Then create 3 repositories:

  • friend-service
  • party-service
  • party-edge-service

First login to Docker

docker login

In push-all.sh change this line to point to your Docker repo:

REPO="cesartl"

Then simply run push-all.sh

At this point you have 3 Docker images in your Docker repository which are ready to be used by Kubernetes.

Step 4: Deploy to K8s

In deploy-k8s.sh change the following line to point to your k8s namespace:

NAMESPACE="cesar"

Then run deploy-k8s.sh

The edge service is configured to have an external load balancer. The effect will depend on your cloud provider. For AWS it will create an ELB endpoint. Give it a few minutes to get ready and then run;

kubectl describe svc edge-service --namespace cesar | grep Ingress

it will give you the public address to your edge service. You can now repeat step 1 by replacing localhost:9999 with your public endpoint!

TODOS

  • Add javadoc and comments in the code
  • Add comment to maven.xml to explain each import
  • Add unit tests for controller
  • Replace Zuul with Spring Cloud gateway and get reactive!

gr8tparties's People

Contributors

cesartl avatar

Watchers

James Cloos avatar Brijesh Singh 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.