All Downloads are FREE. Search and download functionalities are using the official Maven repository.

entry-point.async-event-handler.metrics.metrics-reporter.mustache Maven / Gradle / Ivy

Go to download

Gradle plugin to create a clean application in Java that already works, It follows our best practices!

There is a newer version: 3.20.10
Show newest version
package {{package}}.events.metrics;

import io.micrometer.core.instrument.MeterRegistry;
{{#lombok}}
import lombok.AllArgsConstructor;
{{/lombok}}
import org.reactivecommons.api.domain.Command;
import org.reactivecommons.api.domain.DomainEvent;
import org.reactivecommons.async.api.AsyncQuery;
import org.reactivecommons.async.commons.communications.Message;
import org.reactivecommons.async.commons.ext.CustomReporter;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.time.Duration;

@Service
{{#lombok}}
@AllArgsConstructor
{{/lombok}}
public class MetricsReporter implements CustomReporter {
    private final MeterRegistry registry;
    {{^lombok}}

    public MetricsReporter(MeterRegistry registry) {
        this.registry = registry;
    }
    {{/lombok}}

    @Override
    public void reportMetric(String type, String handlerPath, Long duration, boolean success) {
        String status = success ? "success" : "error";
        registry.timer("async_operation_flow_duration",
                        "exception", "", "type",
                        type, "operation", handlerPath,
                        "status", status)
                .record(Duration.ofMillis(duration));
    }

    @Override
    public Mono reportError(Throwable ex, Message rawMessage, Command message, boolean redelivered) {
        return Mono.empty();
    }

    @Override
    public Mono reportError(Throwable ex, Message rawMessage, DomainEvent message, boolean redelivered) {
        return Mono.empty();
    }

    @Override
    public Mono reportError(Throwable ex, Message rawMessage, AsyncQuery message, boolean redelivered) {
        return Mono.empty();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy