Health for Kafka Binder is always UNKNOWN

妖精的绣舞 提交于 2019-12-31 03:51:17

问题


When I try to activate the health indicator for the kafka binder as explained in Spring Cloud Stream Reference Documentation

the health endpoint returns:

binders":{"status":"UNKNOWN","kafka":{"status":"UNKNOWN"}}}

my configuration contains as documented:

 management.health.binders.enabled=true

I already debugged BindersHealthIndicatorAutoConfiguration and noticed, that no HealthIndicatoris registered in the binderContext. Do I have to register a custom HealthIndicator as bean or what steps are necessary?


回答1:


It looks like a bug in the documentation. By default, the binders health indicators are enabled. If you want to disable, then you would need to specify management.health.binders.enabled=false.

Thanks for reporting this.




回答2:


<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-binder-kafka</artifactId>
        <version>1.3.0.RELEASE</version>
    </dependency>

management.health.binders.enabled = true management.health.kafka.enabled = true

management.endpoint.health.enabled=true management.endpoint.health.show-details=ALWAYS

localhost:8080/actuator/health

{
"status": "UP",
"details": {
    "kafka": {
        "status": "UP"
    },
    "diskSpace": {
        "status": "UP",
        "details": {
            "total": 274622050304,
            "free": 269098790912,
            "threshold": 10485760
        }
    }
}

}

@Component

public class KafkaHealthIndicator implements HealthIndicator { private final Logger log = LoggerFactory.getLogger(KafkaHealthIndicator.class);

private KafkaTemplate<String, String> kafka;

public KafkaHealthIndicator(KafkaTemplate<String, String> kafka) {
    this.kafka = kafka;
}

/**
 * Return an indication of health.
 *
 * @return the health for Kafka.
 */
@Override
public Health health() {
    try {
        kafka.send("kafka-health-indicator", "❥").get(100, TimeUnit.MILLISECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        return Health.down(e).build();
    }
    return Health.up().build();
}

}



来源:https://stackoverflow.com/questions/43842733/health-for-kafka-binder-is-always-unknown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!