1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

magic value refactor for 1.x

This commit is contained in:
fangjian0423 2018-11-29 11:23:04 +08:00
parent 08b1c3ab45
commit ba9bbd6ab6
4 changed files with 80 additions and 47 deletions

View File

@ -21,6 +21,8 @@ package org.springframework.cloud.stream.binder.rocketmq;
*/ */
public interface RocketMQBinderConstants { public interface RocketMQBinderConstants {
String ENDPOINT_ID = "rocketmq_binder";
/** /**
* Header key * Header key
*/ */
@ -33,10 +35,27 @@ public interface RocketMQBinderConstants {
String ACKNOWLEDGEMENT_KEY = "ACKNOWLEDGEMENT"; String ACKNOWLEDGEMENT_KEY = "ACKNOWLEDGEMENT";
/** /**
* Instrumentation key * Instrumentation
*/ */
String LASTSEND_TIMESTAMP = "lastSend.timestamp"; String LASTSEND_TIMESTAMP = "lastSend.timestamp";
String ENDPOINT_ID = "rocketmq_binder"; interface Metrics {
interface Producer {
String PREFIX = "scs-rocketmq.producer.";
String TOTAL_SENT = "totalSent";
String TOTAL_SENT_FAILURES = "totalSentFailures";
String SENT_PER_SECOND = "sentPerSecond";
String SENT_FAILURES_PER_SECOND = "sentFailuresPerSecond";
}
interface Consumer {
String GROUP_PREFIX = "scs-rocketmq.consumerGroup.";
String PREFIX = "scs-rocketmq.consumer.";
String TOTAL_CONSUMED = "totalConsumed";
String CONSUMED_PER_SECOND = "consumedPerSecond";
String TOTAL_CONSUMED_FAILURES = "totalConsumedFailures";
String CONSUMED_FAILURES_PER_SECOND = "consumedFailuresPerSecond";
}
}
} }

View File

@ -16,12 +16,14 @@
package org.springframework.cloud.stream.binder.rocketmq.metrics; package org.springframework.cloud.stream.binder.rocketmq.metrics;
import static com.codahale.metrics.MetricRegistry.name;
import org.springframework.cloud.stream.binder.rocketmq.RocketMQBinderConstants.Metrics.Consumer;
import com.codahale.metrics.Counter; import com.codahale.metrics.Counter;
import com.codahale.metrics.Meter; import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.MetricRegistry;
import static com.codahale.metrics.MetricRegistry.name;
/** /**
* @author juven.xuxb * @author juven.xuxb
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a> * @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
@ -35,10 +37,14 @@ public class ConsumerInstrumentation extends Instrumentation {
public ConsumerInstrumentation(MetricRegistry registry, String baseMetricName) { public ConsumerInstrumentation(MetricRegistry registry, String baseMetricName) {
super(baseMetricName); super(baseMetricName);
this.totalConsumed = registry.counter(name(baseMetricName, "totalConsumed")); this.totalConsumed = registry
this.consumedPerSecond = registry.meter(name(baseMetricName, "consumedPerSecond")); .counter(name(baseMetricName, Consumer.TOTAL_CONSUMED));
this.totalConsumedFailures = registry.counter(name(baseMetricName, "totalConsumedFailures")); this.consumedPerSecond = registry
this.consumedFailuresPerSecond = registry.meter(name(baseMetricName, "consumedFailuresPerSecond")); .meter(name(baseMetricName, Consumer.CONSUMED_PER_SECOND));
this.totalConsumedFailures = registry
.counter(name(baseMetricName, Consumer.TOTAL_CONSUMED_FAILURES));
this.consumedFailuresPerSecond = registry
.meter(name(baseMetricName, Consumer.CONSUMED_FAILURES_PER_SECOND));
} }
public void markConsumed() { public void markConsumed() {

View File

@ -22,6 +22,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.MetricRegistry;
import org.springframework.cloud.stream.binder.rocketmq.RocketMQBinderConstants.Metrics.Consumer;
import org.springframework.cloud.stream.binder.rocketmq.RocketMQBinderConstants.Metrics.Producer;
/** /**
* @author Timur Valiev * @author Timur Valiev
@ -37,7 +39,7 @@ public class InstrumentationManager {
private final Map<String, Instrumentation> healthInstrumentations = new HashMap<>(); private final Map<String, Instrumentation> healthInstrumentations = new HashMap<>();
public ProducerInstrumentation getProducerInstrumentation(String destination) { public ProducerInstrumentation getProducerInstrumentation(String destination) {
String key = "scs-rocketmq.producer." + destination; String key = Producer.PREFIX + destination;
ProducerInstrumentation producerInstrumentation = producerInstrumentations ProducerInstrumentation producerInstrumentation = producerInstrumentations
.get(key); .get(key);
if (producerInstrumentation == null) { if (producerInstrumentation == null) {
@ -48,7 +50,7 @@ public class InstrumentationManager {
} }
public ConsumerInstrumentation getConsumerInstrumentation(String destination) { public ConsumerInstrumentation getConsumerInstrumentation(String destination) {
String key = "scs-rocketmq.consumer." + destination; String key = Consumer.PREFIX + destination;
ConsumerInstrumentation consumerInstrumentation = consumeInstrumentations ConsumerInstrumentation consumerInstrumentation = consumeInstrumentations
.get(key); .get(key);
if (consumerInstrumentation == null) { if (consumerInstrumentation == null) {
@ -59,7 +61,7 @@ public class InstrumentationManager {
} }
public ConsumerGroupInstrumentation getConsumerGroupInstrumentation(String group) { public ConsumerGroupInstrumentation getConsumerGroupInstrumentation(String group) {
String key = "scs-rocketmq.consumerGroup." + group; String key = Consumer.GROUP_PREFIX + group;
ConsumerGroupInstrumentation consumerGroupInstrumentation = consumerGroupsInstrumentations ConsumerGroupInstrumentation consumerGroupInstrumentation = consumerGroupsInstrumentations
.get(key); .get(key);
if (consumerGroupInstrumentation == null) { if (consumerGroupInstrumentation == null) {

View File

@ -16,12 +16,14 @@
package org.springframework.cloud.stream.binder.rocketmq.metrics; package org.springframework.cloud.stream.binder.rocketmq.metrics;
import static com.codahale.metrics.MetricRegistry.name;
import org.springframework.cloud.stream.binder.rocketmq.RocketMQBinderConstants.Metrics.Producer;
import com.codahale.metrics.Counter; import com.codahale.metrics.Counter;
import com.codahale.metrics.Meter; import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.MetricRegistry;
import static com.codahale.metrics.MetricRegistry.name;
/** /**
* @author juven.xuxb * @author juven.xuxb
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a> * @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
@ -35,10 +37,14 @@ public class ProducerInstrumentation extends Instrumentation {
public ProducerInstrumentation(MetricRegistry registry, String baseMetricName) { public ProducerInstrumentation(MetricRegistry registry, String baseMetricName) {
super(baseMetricName); super(baseMetricName);
this.totalSent = registry.counter(name(baseMetricName, "totalSent"));
this.totalSentFailures = registry.counter(name(baseMetricName, "totalSentFailures")); this.totalSent = registry.counter(name(baseMetricName, Producer.TOTAL_SENT));
this.sentPerSecond = registry.meter(name(baseMetricName, "sentPerSecond")); this.totalSentFailures = registry
this.sentFailuresPerSecond = registry.meter(name(baseMetricName, "sentFailuresPerSecond")); .counter(name(baseMetricName, Producer.TOTAL_SENT_FAILURES));
this.sentPerSecond = registry
.meter(name(baseMetricName, Producer.SENT_PER_SECOND));
this.sentFailuresPerSecond = registry
.meter(name(baseMetricName, Producer.SENT_FAILURES_PER_SECOND));
} }
public void markSent() { public void markSent() {