Health for Kafka Binder is always UNKNOWN

前端 未结 2 1501
你的背包
你的背包 2021-01-21 12:40

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

the health endpoint returns:



        
相关标签:
2条回答
  • 2021-01-21 13:08
    <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();
    }
    

    }

    0 讨论(0)
  • 2021-01-21 13:19

    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.

    0 讨论(0)
提交回复
热议问题