如何创建/定制spring boot执行器以公开我的camunda应用程序的应用程序健康检查和诊断?

bwntbbo3  于 2021-07-06  发布在  Java
关注(0)|答案(2)|浏览(472)

我被要求为我的camunda引擎/bpmn工具创建Spring启动执行器。这样我们就可以通过springactuator公开各种应用程序的健康检查和诊断。
这应该扩展到公开camunda的运行状况、配置和度量。你知道怎么做吗?

qfe3c7zg

qfe3c7zg1#

我已经能够定制现有的healthcheck执行器。为希望在这些项目中自定义的人共享下面的代码。

@Component
public class X extends AbstractHealthIndicator {
    @Autowired
    public JobExecutor jobExecutor;

    @Override
    protected void doHealthCheck(Builder builder) throws Exception {
        boolean active = jobExecutor.isActive();
        if (active) {
            builder = builder.up();
        } else {
            builder = builder.down();
        }
        builder.withDetail("jobExecutor", healthDetails(jobExecutor));
    }

    private Details healthDetails(JobExecutor jobExecutor) {
        final DetailsBuilder builder = Details.builder().name(jobExecutor.getName())
                .lockOwner(jobExecutor.getLockOwner()).lockTimeInMillis(jobExecutor.getLockTimeInMillis())
                .maxJobsPerAcquisition(jobExecutor.getMaxJobsPerAcquisition())
                .waitTimeInMillis(jobExecutor.getWaitTimeInMillis());

        for (ProcessEngineImpl processEngineImpl : jobExecutor.getProcessEngines()) {
            builder.processEngineName(processEngineImpl.getName());
        }

        return builder.build();
    }

}
a5g8bdjr

a5g8bdjr2#

假设您使用的是camunda spring boot starter:starter附带了processengine和jobecutor的两个默认运行状况指示器,请看一下:
https://github.com/camunda/camunda-bpm-spring-boot-starter/tree/master/starter/src/main/java/org/camunda/bpm/spring/boot/starter/actuator

@Override
  protected void doHealthCheck(Builder builder) throws Exception {
    boolean active = jobExecutor.isActive();
    if (active) {
      builder = builder.up();
    } else {
      builder = builder.down();
    }
    builder.withDetail("jobExecutor", Details.from(jobExecutor));
  }

这应该给你一个如何实现Spring的想法 AbstractHealthIndicator ,访问camunda组件并将其用于健康检查。

相关问题