当前位置: 首页 > wzjs >正文

免费ppt模板 网站开发微信小程序开发一个多少钱啊

免费ppt模板 网站开发,微信小程序开发一个多少钱啊,建材销售网站手机模板,嘉里建设网站配置是 Spring Boot 应用程序中的一部分,主要用于配置服务端口、应用名称、Consul 服务发现以及健康检查等功能。以下是对每个部分的详细解释: 1. server.port server:port: 8080作用:指定 Spring Boot 应用程序运行的端口号。解释&#xf…

配置是 Spring Boot 应用程序中的一部分,主要用于配置服务端口、应用名称、Consul 服务发现以及健康检查等功能。以下是对每个部分的详细解释:

1. server.port

server:port: 8080
  • 作用:指定 Spring Boot 应用程序运行的端口号。
  • 解释:这里将应用程序的端口设置为 8080

2. spring.application.name

spring:application:name: ConsumerServer
  • 作用:设置 Spring Boot 应用程序的名称。
  • 解释:这里将应用程序的名称设置为 ConsumerServer,通常用于服务发现和监控。

3. Consul 配置

spring:cloud:consul:host: 192.168.102.20port: 8500discovery:enabled: truehostname: ${spring.cloud.client.ip-address}instance-id: ${spring.application.name}:${spring.cloud.consul.discovery.hostname}:${server.port}health-check-interval: 15sregister: trueregister-health-check: trueservice-name: ${spring.application.name}health-check-critical-timeout: 10s
  • hostport

    • 作用:指定 Consul 服务的地址和端口。
    • 解释:这里将 Consul 服务的地址设置为 192.168.102.20,端口设置为 8500
  • discovery.enabled

    • 作用:启用 Consul 的服务发现功能。
    • 解释:设置为 true 表示启用服务发现。
  • hostname

    • 作用:指定当前服务的主机名。
    • 解释:这里使用 ${spring.cloud.client.ip-address},表示使用当前机器的 IP 地址作为主机名。
  • instance-id

    • 作用:指定服务实例的唯一标识。
    • 解释:这里使用 ${spring.application.name}:${spring.cloud.consul.discovery.hostname}:${server.port},即 应用名称:主机名:端口号 的组合。
  • health-check-interval

    • 作用:设置健康检查的间隔时间。
    • 解释:这里设置为 15s,表示每 15 秒进行一次健康检查。
  • registerregister-health-check

    • 作用:控制是否将服务注册到 Consul,并启用健康检查。
    • 解释:这里都设置为 true,表示启用服务注册和健康检查。
  • service-name

    • 作用:指定服务的名称。
    • 解释:这里使用 ${spring.application.name},即 ConsumerServer
  • health-check-critical-timeout

    • 作用:设置健康检查的超时时间。
    • 解释:这里设置为 10s,表示如果健康检查在 10 秒内没有响应,则认为服务不可用。

4. 管理端点配置

management:endpoints:web:exposure:include: "*"endpoint:health:show-details: always
  • endpoints.web.exposure.include

    • 作用:指定哪些管理端点可以通过 Web 访问。
    • 解释:这里设置为 "*",表示所有管理端点都可以通过 Web 访问。
  • endpoint.health.show-details

    • 作用:控制健康检查端点是否显示详细信息。
    • 解释:这里设置为 always,表示总是显示详细信息。

总结

这段配置的主要功能如下:

  1. 服务端口:将应用程序的端口设置为 8080
  2. 应用名称:将应用程序的名称设置为 ConsumerServer
  3. Consul 配置
    • 启用 Consul 服务发现。
    • 将服务注册到 Consul,使用 IP 地址作为主机名。
    • 每 15 秒进行一次健康检查,超时时间为 10 秒。
  4. 管理端点配置
    • 允许通过 Web 访问所有管理端点。
    • 健康检查端点始终显示详细信息。

通过这些配置,应用程序可以与 Consul 集成,实现服务发现和健康检查功能,并且管理端点可以通过 Web 访问,方便监控和管理。

在 Spring Boot 应用程序中,使用 Consul 的配置主要通过 Spring Cloud Consul 模块来实现。这些配置在启动时会自动生效,而无需在代码中手动实现。以下是详细的解释:

1. 引入依赖

首先,需要在项目的 pom.xml 文件中引入 Spring Cloud Consul 的依赖。例如:

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

或者在 Gradle 中:

implementation 'org.springframework.cloud:spring-cloud-starter-consul-discovery'

2. 配置文件中的 Consul 设置

application.ymlapplication.properties 文件中配置 Consul 的相关参数,如你提供的配置:

spring:cloud:consul:host: 192.168.102.20port: 8500discovery:enabled: truehostname: ${spring.cloud.client.ip-address}instance-id: ${spring.application.name}:${spring.cloud.consul.discovery.hostname}:${server.port}health-check-interval: 15sregister: trueregister-health-check: trueservice-name: ${spring.application.name}health-check-critical-timeout: 10s

3. 自动配置和生效机制

Spring Cloud Consul 会自动处理这些配置,并在应用启动时完成以下工作:

3.1 服务注册
  • 自动注册:当 spring.cloud.consul.discovery.enabled=true 时,Spring Cloud Consul 会自动将当前服务注册到 Consul。
  • 注册信息
    • 服务名称:通过 spring.application.name 配置。
    • 实例 ID:通过 spring.cloud.consul.discovery.instance-id 配置。
    • 主机名:通过 spring.cloud.consul.discovery.hostname 配置。
    • 端口:通过 server.port 配置。
3.2 健康检查
  • 自动健康检查:Spring Cloud Consul 会根据 spring.cloud.consul.discovery.health-check-intervalspring.cloud.consul.discovery.health-check-critical-timeout 配置,定期向 Consul 报告服务的健康状态。
  • 健康检查路径:默认情况下,Spring Boot 的 /actuator/health 端点会被用作健康检查路径。如果需要自定义路径,可以通过 spring.cloud.consul.discovery.health-check-path 配置。
3.3 服务发现
  • 自动发现:Spring Cloud Consul 会自动从 Consul 获取其他服务的实例信息。你可以在代码中通过 @LoadBalanced 注解的 RestTemplateWebClient 来调用其他服务,而无需手动管理服务地址。

4. 代码中的使用

虽然大部分配置可以通过 YAML 文件完成,但在某些情况下,你可能需要在代码中使用 Consul 提供的服务发现功能。例如:

使用 RestTemplate 调用其他服务
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;public class ServiceClient {@Autowiredprivate RestTemplate restTemplate;public String callService() {// 调用名为 "OtherService" 的服务return restTemplate.getForObject("http://OtherService/api/endpoint", String.class);}
}

在配置类中:

@Bean
@LoadBalanced
public RestTemplate restTemplate() {return new RestTemplate();
}
使用 WebClient 调用其他服务
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.reactive.function.client.WebClient;public class ServiceClient {@Autowiredprivate WebClient.Builder webClientBuilder;public Mono<String> callService() {// 调用名为 "OtherService" 的服务return webClientBuilder.build().get().uri("http://OtherService/api/endpoint").retrieve().bodyToMono(String.class);}
}

5. 总结

  • 自动配置:Spring Cloud Consul 会自动处理服务注册、健康检查和服务发现,无需手动实现。
  • 代码使用:虽然大部分功能通过配置生效,但你可以在代码中通过 RestTemplateWebClient 调用其他服务。
  • 优势:通过配置文件和 Spring Cloud Consul 的自动配置机制,可以大大简化服务发现和健康检查的实现。

通过这种方式,Spring Boot 应用程序可以无缝集成到 Consul 提供的服务发现和健康检查体系中。

http://www.dtcms.com/wzjs/326590.html

相关文章:

  • 昆明网站建设企业关键词排名查询网站
  • 民族文化网站建设的作用成都seo培
  • 网网站建设设计公司百度关键词搜索排名多少钱
  • 个人博客网站教程搜索引擎调词平台哪个好
  • 做网站费用记入什么会计科目产品网络营销推广方案
  • html5移动网站开发实例今日国际新闻大事
  • 广州网站设计软件大型门户网站建设
  • 九江网站建设制作深圳百度推广排名优化
  • html网站怎么做合肥关键词排名工具
  • 一个网站源代码概多大拼多多跨境电商平台
  • 泰州网站制作推广线下推广团队
  • 网站建设静态代码北京seo网络优化师
  • 中国建设银行官方网站网上银行网站seo分析报告
  • 做盗链网站手机最新产品新闻
  • 温州企业网站建设公司b站2023年免费入口
  • 湖南住建云网站2022当下社会热点话题
  • 自动化毕设题目网站开发互联网营销的十五种方式
  • wordpress更改网站url无法访问比较靠谱的推广公司
  • 苏州建站模板系统企业营销策划案例
  • 阜阳网站开发汕头网站建设平台
  • 杭州租房网站建设产品营销策划方案3000字
  • 做网站建设的平台教你如何快速建站
  • 宜春做网站哪里好中山seo推广优化
  • 网站建设 长春企业在线培训系统
  • 独立站店铺怎么注册鸡西seo顾问
  • 重庆专业网站推广平台百度app官方下载安装
  • 手机电影网站怎样做搜索引擎优化排名技巧
  • wordpress博客页面无法显示深圳aso优化
  • php制作网站开发靖江seo要多少钱
  • 编辑网站的软件手机石家庄网站建设方案