【问题标题】:Is it possible for one app to check health of the other using any features of Spring framework?一个应用程序是否可以使用 Spring 框架的任何功能检查另一个应用程序的运行状况?
【发布时间】:2019-03-22 11:57:14
【问题描述】:

我有两个正在运行的应用程序实例。一个应用程序是否可以使用 Spring 框架的任何功能检查另一个应用程序的运行状况?

【问题讨论】:

  • 同一个应用的两个实例是什么意思?你能详细说明一下吗?

标签: java spring-security spring-boot-actuator health-monitoring spring-boot-starter


【解决方案1】:

是的。您可以将 Health Indicator 与 Actuator 一起使用

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

可用的端点

/health /info /metrics /trace

可以返回

{
    "status" : "UP"
}

{
    "status" : "DOWN",
    "myHealthCheck" : {
        "status" : "DOWN",
        "Error Code" : 1
     },
     "diskSpace" : {
         "status" : "UP",
         "free" : 209047318528,
         "threshold" : 10485760
     }
}

在此处阅读更多信息https://www.baeldung.com/spring-boot-actuators

【讨论】:

    【解决方案2】:

    详细说明 Hitham 的答案:

    假设应用 A 需要报告应用 B 的状态。因此,似乎 A 依赖于 B 提供某些服务?

    在任何情况下,您都可以在 A 中实现 HealthIndicator,尝试在 B 上调用您需要的服务,使用一些良性、无副作用的操作。

    【讨论】:

    • 他说同一个 App 的 2 个实例,你说它们是两个不同的应用程序
    • 是的。我猜他必须使用弹簧@Profile 来激活那些健康检查
    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 2015-08-11
    相关资源
    最近更新 更多