Skip to content

sups149/spring-boot-kafka-demo

Repository files navigation

spring-boot-kafka-demo

Kafka messaging with spring boot

Actuator details

Enable all actuator endpoints

Property

management.endpoints.web.exposure.include=*

Endpoint

http://localhost:8080/actuator

Exclude endpoints

Property

management.endpoints.web.exposure.exclude=info,beans

Disable endpoint exposure by default

Property

management.endpoints.enabled-by-default=false

Enabling specific endpoint when the default exposure is disabled

Property

Format
management.endpoint.{EndpointName}.enabled=true/false

Example

management.endpoint.health.enabled=true

Endpoint

http://localhost:8080/actuator/health

Enable extensive details of an endpoint

Property

management.endpoint.health.show-details=ALWAYS

Grouping endpoint output

Properties

Format
management.endpoint.health.group.{group-name}.include=ping,diskSpace

Example\

management.endpoint.health.group.health-group.include=ping,diskSpace

Endpoint

Format
http://localhost:8080/actuator/health/{group-name}

Example:
http://localhost:8080/actuator/health/health-group

Overriding the actuator base path

Properties

management.endpoints.web.base-path=/manage

Example:
http://localhost:8080/actuator/health/health-group

Map endpoint to different path

Property

Format:\

management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.{endpoint}={mapped-path}

Example:\

management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=healthcheck

Custimized health monitor

We need to implement HealthIndicator interface

@Component
public class KafkaHealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
        if(isKafkaHealthy()) {
            return Health.up().withDetail("Kafka", "Healthy").build();
        }
        return Health.down().withDetail("Kafka", "Unhealthy").build();
    }
}

Custom endpoint

import java.util.HashMap;

@Endpoint(id = "custom")
@Component
public class CustomActEndpoint {
    @ReadOperation
    public Map<String, String> customEndpoint(String id) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        return map;
    }
}

Access the custom endpoint with:
http://localhost:8080/actuator/custom

Prometheus

Install prometheus with docker

docker pull prom/prometheus
docker run -d --name=prometheus -p 9090:9090 -v {path_of_prometheus.yml_file}:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml

About

Kafka messaging with spring boot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages