-
Notifications
You must be signed in to change notification settings - Fork 930
[ISSUE #323] Support the expansion of metrics data statistics in RocketMQ-Spring. #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1c5669b
8b070b6
b52eaa8
958f1ba
0a435b2
efc25a7
6c7a2de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.rocketmq.samples.springboot; | ||
|
||
import org.apache.rocketmq.spring.metric.MetricExtension; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class AtomicLongMetricExtension implements MetricExtension { | ||
|
||
private final static Logger LOGGER = LoggerFactory.getLogger(AtomicLongMetricExtension.class); | ||
|
||
private final Map<String, AtomicLong> consumerMessageCountMap = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void addProducerMessageCount(String topic, int count) { | ||
//nothing | ||
} | ||
|
||
@Override | ||
public void addConsumerMessageCount(String topic, EConsumerMode consumerMode, int count) { | ||
String key = topic + "_" + consumerMode.name(); | ||
AtomicLong atomicLong = consumerMessageCountMap.computeIfAbsent(key, t -> new AtomicLong()); | ||
LOGGER.info("The count of {} consumer messages for {} is {}" | ||
, consumerMode.name(), topic, atomicLong.addAndGet(count)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.apache.rocketmq.samples.springboot.AtomicLongMetricExtension |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.rocketmq.samples.springboot; | ||
|
||
import org.apache.rocketmq.spring.metric.MetricExtension; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class AtomicLongMetricExtension implements MetricExtension { | ||
|
||
private final static Logger LOGGER = LoggerFactory.getLogger(AtomicLongMetricExtension.class); | ||
|
||
private final Map<String, AtomicLong> producerMessageCountMap = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void addProducerMessageCount(String topic, int count) { | ||
AtomicLong atomicLong = producerMessageCountMap.computeIfAbsent(topic, t -> new AtomicLong()); | ||
LOGGER.info("The count of producer messages for {} is {}", topic, atomicLong.addAndGet(count)); | ||
} | ||
|
||
@Override | ||
public void addConsumerMessageCount(String topic, EConsumerMode consumerMode, int count) { | ||
//nothing | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.apache.rocketmq.samples.springboot.AtomicLongMetricExtension |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.rocketmq.spring.core; | ||
|
||
import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer; | ||
import org.apache.rocketmq.remoting.RPCHook; | ||
|
||
public class DefaultLitePullConsumerWithTopic extends DefaultLitePullConsumer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DefaultLitePullConsumerWithTopic is not a rational name here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compared with DefaultLitePullConsumer, this class just has one more Topic attribute. So, I named this class DefaultLitePullConsumerWithTopic. Do you have any better suggestions for the naming of this class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not make a new class here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where can this new class be maked? What's your suggestion? |
||
|
||
private String topic; | ||
|
||
public DefaultLitePullConsumerWithTopic(final String consumerGroup) { | ||
super(consumerGroup); | ||
} | ||
|
||
public DefaultLitePullConsumerWithTopic(final String consumerGroup, RPCHook rpcHook) { | ||
super(consumerGroup, rpcHook); | ||
} | ||
|
||
public String getTopic() { | ||
return topic; | ||
} | ||
|
||
public void setTopic(String topic) { | ||
this.topic = topic; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.rocketmq.spring.metric; | ||
|
||
public interface MetricExtension { | ||
|
||
enum EConsumerMode { | ||
/** | ||
* pull mode | ||
*/ | ||
Pull, | ||
/** | ||
* push mode | ||
*/ | ||
Push, | ||
} | ||
|
||
/** | ||
* Add current count of message from the producer. | ||
* | ||
* @param topic topic name | ||
* @param count count of message | ||
*/ | ||
void addProducerMessageCount(String topic, int count); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int or long should be consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter type is always int, and long is not used. |
||
|
||
/** | ||
* Add current count of message from the consumer. | ||
* | ||
* @param topic topic name | ||
* @param consumerMode consumer mode | ||
* @param count count of message | ||
*/ | ||
void addConsumerMessageCount(String topic, EConsumerMode consumerMode, int count); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you add prefix placeholder before the root directory /src?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it. When running
mvn -B clean apache-rat:check
and building RocketMQ Spring Boot, the rocketmq-spring-boot-samples project will also be checked. If I do not add the prefix placeholder, an unapproved license error will be reported. Like this: https://travis-ci.org/github/apache/rocketmq-spring/builds/748732956