@Override
    protected void doProcess(Exchange exchange, MetricsEndpoint endpoint, MetricRegistry registry, String metricsName)
            throws Exception {
        Gauge<?> gauge = registry.getGauges().get(metricsName);
        if (gauge instanceof CamelMetricsGauge) {
            CamelMetricsGauge camelMetricsGauge = (CamelMetricsGauge) gauge;
            Object subject = exchange.getIn().getHeader(HEADER_GAUGE_SUBJECT, Object.class);
            if (subject != null) {
                camelMetricsGauge.setValue(subject);
            }
        } else {
            Object subject = exchange.getIn().getHeader(HEADER_GAUGE_SUBJECT, Object.class);
            Object finalSubject = subject != null ? subject : endpoint.getSubject();
            if (finalSubject != null) {
                registry.register(metricsName, new CamelMetricsGauge(finalSubject));
            } else {
                LOG.info("No subject found for Gauge \"{}\". Ignoring...", metricsName);
            }
        }
    }
@Test
    public void testProcessWithHeaderValues() throws Exception {
        when(in.getHeader(HEADER_GAUGE_SUBJECT, Object.class)).thenReturn(VALUE_HEADER);
        producer.doProcess(exchange, endpoint, registry, METRICS_NAME_HEADER);
        verify(in, times(1)).getHeader(HEADER_GAUGE_SUBJECT, Object.class);
        verify(registry, times(1)).register(eq(METRICS_NAME), argThat(new ArgumentMatcher<CamelMetricsGauge>() {
            @Override
            public boolean matches(CamelMetricsGauge argument) {
                return VALUE.equals(argument.getValue());
            }
        }));
        verify(registry, times(1)).register(eq(METRICS_NAME_HEADER), argThat(new ArgumentMatcher<CamelMetricsGauge>() {
            @Override
            public boolean matches(CamelMetricsGauge argument) {
                return VALUE_HEADER.equals(argument.getValue());
            }
        }));
    }