Git Product home page Git Product logo

moments's Introduction

This project uses Spring Cloud to build a microservice structured Single Page Application.

Table of contents

Project Structure

Description

This project uses several Spring Cloud modules to construct a simple microservice structured web application.

  • config-server uses Spring Cloud Config Server to manage configurations
  • eureka-server uses Spring Cloud Netflix Eureka to support service registry and discovery
  • gateway-server uses Spring Cloud Gateway to support gateway, authentication and web portal are also included in this module
  • message-service is a Spring Boot Application microservice which registers to eureka-server and requests can be routed from gateway-server

For the front end under gateway-server, it's developed with Vue.js.

Detailed structure tree

    moments
    ├── config-server
    │   └── src
    │       └── main
    │           ├── java
    │           └── resources
    │               ├── shared         // configuration files
    │               └── bootstrap.yml 
    │
    ├── eureka-server                  // eureka server for service registry and discovery
    │   └── src
    │       └── main
    │           ├── java
    │           └── resources
    │               └── bootstrap.yml 
    │
    ├── gateway-server
    │   └── src
    │       └── main
    │           ├── java
    │           ├── resources
    │           │   ├── static
    │           │   │    └── dist      // webpack bundled resources after npm build
    │           │   └── bootstrap.yml 
    │           └── webapp             // front end resources
    │               └── src
    │                   ├── api
    │                   ├── components // Vue components
    │                   └── lib
    │
    ├── message-service
    │   └── src
    │       └── main
    │           ├── java
    │           └── resources
    │               └── bootstrap.yml 
    │
    └── moments-parent                // parent maven pom for other modules mainly for dependency management

How to run

Run with maven

  1. Package the gateway-server front end resources.

    $ cd gateway-server
    $ npm install
    $ npm run build
    
    $ cd .. && mvn clean install
  2. Start servers one after another under each module folder:

    config-server, eureka-server, message-service, gateway-server

    $ cd config-server
    $ mvn spring-boot:run
    
    $ cd eureka-server
    $ mvn spring-boot:run
    
    $ cd message-service
    $ mvn spring-boot:run
    
    $ cd gateway-server
    $ mvn spring-boot:run
  3. Dockerize your microservice

    config-server:

    $ cd config-server
    $ docker build . -t configserver --build-arg PACKAGENAME=config-server-0.0.1-SNAPSHOT.jar
    $ docker run -h config-server -p 8888:8888 -it configserver:latest

How to access

  1. Gateway:

    http://localhost:8080/

    Log in with user/password or admin/password

  2. Message service through gateway

    http://localhost:8080/message/get

    http://localhost:8080/message/admin/get // Only accessible by admin

How to develop

Modules beside gateway-server are normal Spring Boot applications, no special configurations are configured for development.

Develop gateway front end

In the gateway-server module, webpack is used to bundle the web resources. In order to develop without frequently re-packaging the web resources and restart Spring Boot application server, this project uses webpack dev server for local development and auto refresh.

Under gateway-server module root, start gateway server:

$ mvn spring-boot:run

Start webpack dev server:

$ npm run start

Access http://localhost:9090.

FAQ

Why Spring Webflux is used in gateway-server but not Spring MVC?

In this project, websocket is used, Spring Netflix Zuul does not support websocket, so Spring Cloud Gateway is used to support websocket. But Spring Cloud Gateway cannot work well with Spring MVC with warning message Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency. So Spring Webflux is used.

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.