zoukankan      html  css  js  c++  java
  • 服务注册与发现---spring cloud

    Eureka基本架构
    Register Service :服务注册中心,它是一个 Eureka Server ,提供服务注册和发现的功能。
    Provider Service :服务提供者,它是 Eureka Client ,提供服务
    Consumer Service :服务消费者,它是 Eureka Cient ,消费服务
    测试代码
    1.服务端
    appliation.yml
    server :
    port : 8761
    eureka :
    instance :
    hostname : localhost
    client :
    registerWithEureka: false
    fetchReg stry false
    servi ceUrl :
    defaultZone :
    http://$(eureka instance hostname ♀( server port)/eureka/

    @EnableEurekaServer
    @SpringBootApplication
    public class EurekaServerApplication (
    public stat VO mai 口( String [] args) (
    SpringApplication run(EurekaServerApplicatio class args) ;
    }
    }

    2.客户端
    application.yml配置文件

    eureka:
    client :
    serviceUrl:
    defaultZone : http://localhost:8761/eureka/
    server:
    port : 8762
    spring :
    application :
    name . eureka-client

    @SpringBootApplication
    @EnableEurekaClient
    public class EurekaClientApplication{
    public static void main (String [] args) (
    SpringApplication.run(EurekaClientApplication . class, args);
    }
    }

    @RestController
    public class HiController {
    @Value (”${ server.port)”)
    String port;
    @GetMapping (”/ hi”)
    public String home (@RequestParam String name) {
    return ” hi ”+name+”, l am from port : ” +port;
    }
    }

    3.Eureka 的一些概念
    服务注册,服务续约,获取服务注册列表,服务下线,服务剔除

  • 相关阅读:
    关于视图的一些认识
    __autoload()尝试加载未定义的类
    php正则逆向引用与子模式分析
    常州day1p4
    Hello World
    Linux安装配置jdk
    使用http3访问服务
    后端访问sso后,如何返回前端vue页面(后端redirect跳转,vue代理,axios带参)
    linux常用命令
    使用nexus搭建npm私服
  • 原文地址:https://www.cnblogs.com/dibinbin/p/9263620.html
Copyright © 2011-2022 走看看