12

在我的 DropWizard ( v0.7.0 ) 应用程序中,我有DummyHealthCheck这样的:

public class DummyHealthCheck extends HealthCheck {
    @Override
    protected Result check() throws Exception {
        return Result.healthy();
    }
}

然后在我的主要Application实现中:

public class MyApplication extends Application<MyConfiguration> {
    @Override
    public void run(MyConfiguration configuration, Environment environment)
            throws Exception {
        environment.jersey().register(new DummyHealthCheck());
    }
}

当我启动服务器时,它成功启动(没有异常/错误),但是我收到以下消息:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!    THIS APPLICATION HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW      !
!     IF IT DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE      !
!    LETTING YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH OF YOUR    !
!         APPLICATION'S DEPENDENCIES WHICH FULLY (BUT LIGHTLY) TESTS IT.       !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

但是当我去时,http://localhost:8081/healthcheck我看到:

{"deadlocks":{"healthy":true}}
  1. 这里发生了什么?如何注册我的健康检查?
  2. 此外,我已将 DropWizard 配置为在端口 8443 上使用 SSL(自签名);我已经验证这适用于我的正常端点。然而,令我惊讶的是,我的管理应用程序仍然通过 HTTP 暴露在 8081 上。我如何也为 HTTPS 配置它?
4

1 回答 1

14

问题一:

您无需在 Jersey 注册它,因为健康检查是 DropWizard 特有的。他们应该注册如下

environment.healthChecks().register("dummy", new DummyHealthCheck());

如此所述。如果它如上注册的,你会看到

{"deadlocks":{"healthy":true}, "dummy":{"healthy":true}}

问题2:

我假设你已经做了类似的事情

server:
  applicationConnectors:
    - type: https
      port: 8443
      keyStorePath: example.keystore
      keyStorePassword: example
      validateCerts: false

在您的 yaml 中,如此处所示。那只是为了应用程序。您还需要配置管理员

server:
  applicationConnectors:
  - ...
  adminConnectors:
  - type: https
    port: 8444    // should a different port from the application
    keyStorePath: example.keystore
    keyStorePassword: example
    validateCerts: false
于 2014-12-11T20:40:56.340 回答