• springboot集成consul


    1     服务提供者

    1.1   父级Pom

    <spring-cloud.version>Hoxton.SR6</spring-cloud.version>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>

    1.2   Web

    1.2.1 Pom

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        <optional>true</optional>
    </dependency>

    1.2.2 启动类

    @EnableDiscoveryClient

     

    1.2.3 配置文件

    cloud:
        consul:
          host: 192.168.250.44
          port: 8500
          discovery:
            register: true
            serviceName: ${spring.application.name}
            healthCheckPath: /actuator/health
    #        healthCheckInterval: 1s
           
    instanceId: ${spring.application.name}
            ip-address: ${spring.cloud.client.ipaddress}
            prefer-ip-address: true

    1.3   Api

    1.3.1 Pom

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
        <optional>true</optional>
    </dependency>

    1.3.2 接口样例

    • Api

     

    • Controller

     

    2     服务消费者

    2.1   父级Pom

    <spring-cloud.version>Hoxton.SR6</spring-cloud.version>

     

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>

    2.2   Web

    2.2.1 Pom

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        <optional>true</optional>
    </dependency>

    2.2.2 启动类

    @EnableFeignClients(basePackages = {"com.oceandata.od_idauth.api.*"})

    2.2.3 配置文件

    cloud:
      consul:
        host: 192.168.250.44
        port: 8500
        discovery:
          register: false
          serviceName: ${spring.application.name}
          healthCheckPath: /actuator/health
          instanceId: ${spring.application.name}
          ip-address: ${spring.cloud.client.ipaddress}
          prefer-ip-address: true

     

  • 相关阅读:
    装饰器和表达生成式
    函数
    字符编码
    函数基础
    列表,字典与集合
    Linux Semaphore
    tp5安装easyWeChat
    wx.request
    小程序设计规范
    小程序的概念和特点
  • 原文地址:https://www.cnblogs.com/niuniu0108/p/13358851.html
Copyright © 2020-2023  润新知