Giter Club home page Giter Club logo

spring-cloud-netflix-1's Introduction

Spring Cloud Netflix 分布式微服务实践

基于美国Netflix公司开源的分布式应用开发框架, 使用Config配置中心,Eureka服务注册发现,Feign服务调用,Zuul微服务网关,Ribbon负载均衡, Hystrix服务容错保护/断路器,Spring Boot Admin服务管控

eureka-server 注册中心

启动应用后,打开 http://localhost:8761

可以看到启动的服务

服务注册中心

config-server 配置中心

该服务将git仓库中的配置文件以接口形式提供出去,客户端可以获取并加载配置。

例如打开 http://localhost:3600/eureka/default ,获取eureka配置信息:

{
    "name": "eureka",
    "profiles": [
        "default"
    ],
    "label": null,
    "version": "a716ea609caaa0811387bcc616227b42e6094b26",
    "state": null,
    "propertySources": [
        {
            "name": "https://github.com/yunTerry/spring-cloud-netflix/config-repo/eureka.yml",
            "source": {
                "spring.application.name": "eureka-server",
                "server.port": 8761,
                "eureka.client.register-with-eureka": false,
                "eureka.client.fetch-registry": false,
                "management.security.enabled": false
            }
        }
    ]
}

zuul 微服务网关

用serviceId代替URL,实现动态路由

通过Zuul过滤器进行请求鉴权认证,拦截不合法请求,同时也可以实现API限流操作。

token-service 服务提供者

token认证服务,提供生成token和验证token的接口

@GetMapping("/token/generate/{uid}")
String getToken(@PathVariable String uid);

@GetMapping("/token/verify")
boolean verify(@RequestParam String token);

user-service 服务消费者

调用用户相关服务的时候,会消费token认证服务,使用Feign调用服务,通过Hystrix提供容错保护

http://localhost:4000/user-service/login 发POST请求

登录或注册成功返回token

{
    "code": 0,
    "msg": "login success",
    "data": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3NjVhNWEyYy1hYzhhLTQxNDctYjI2Yy0zNTFlYTA0NjI4OGEiLCJleHAiOjE1MjA1OTMzODF9.NMUjrRk7MsAROuq1OLOUM9WOefgkZmg5_M_mjiSVa0Cz-SunY2ucgxEvOGdKW7U1AVteNVVtD1v_cQlwA_wREQ"
}

把token放在请求头,获取用户信息 http://localhost:4000/user-service/user/info

{
    "code": 0,
    "msg": "success",
    "data": {
        "id": "765a5a2c-ac8a-4147-b26c-351ea046288a",
        "name": "aa",
        "sex": "boy",
        "img": "http://img.com/aa32.jpg",
        "age": 20
    }
}

admin-server 服务管控

打开 http://localhost:5033

admin

admin

Zipkin 服务追踪

http://localhost:5500/zipkin/ 可以查看服务链路追踪

服务调用链路

服务调用时间

调用详情

spring-cloud-netflix-1's People

Contributors

yunterry 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.