-
Notifications
You must be signed in to change notification settings - Fork 900
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
[ISSUE #323] Support the expansion of metrics data statistics in RocketMQ-Spring. #324
base: master
Are you sure you want to change the base?
Conversation
@@ -176,9 +176,10 @@ | |||
<exclude>.github/**</exclude> | |||
<exclude>src/test/resources/certs/*</exclude> | |||
<exclude>src/test/**/*.log</exclude> | |||
<exclude>src/test/resources/META-INF/service/*</exclude> | |||
<exclude>**/src/main/resources/META-INF/services/*</exclude> |
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
...ume-demo/src/main/java/org/apache/rocketmq/samples/springboot/AtomicLongMetricExtension.java
Outdated
Show resolved
Hide resolved
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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Where can this new class be maked? What's your suggestion?
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQTemplate.java
Outdated
Show resolved
Hide resolved
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/metric/EConsumerMode.java
Outdated
Show resolved
Hide resolved
* @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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter type is always int, and long is not used.
import java.util.List; | ||
import java.util.ServiceLoader; | ||
|
||
public class MetricExtensionProvider { |
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.
Do not make class by yourself. I strongly recommend you use a similar service loader mode in RocketMQ[1]. It has many backoff strategies and verified in the production environment.
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.
The ServiceProvider is in the broker module, RocketMQ-Spring has no dependency on the broker module, so it cannot be used directly.
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.
You could copy and make some improvements. Pls make a reference description when you do it .
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.
ServiceLoader is a simple Service Provder Framework provided since JDK 1.6. I think the reference description is this: https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html
|
||
@Test | ||
public void testAddProducerMessageCount() { | ||
MetricExtensionProvider.addProducerMessageCount("topic1", 111); |
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.
It could be helpful for your code convincible if you could make more corner cases, such as have you simulated the count of failures?
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.
This unit test is mainly used to test whether the SPI of MetricExtensionProvider is running normally.The scenario where the counting fails you mentioned was considered by the developer when implementing the MetricExtension interface.
Do we consider the possibility of using aop to finish this feature? @RongtongJin Would you like to help to design here? |
What is the purpose of the change
Support the expansion of metrics data statistics in RocketMQ-Spring. This feature can enable:
Brief changelog
Created an interface called MetricExtension to record the number of messages produced or consumed. By obtaining the implementation of this interface through SPI, developers can easily write their own metrics data statistics method.
Verifying this change
Follow this checklist to help us incorporate your contribution quickly and easily. Notice,
it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR
.[ISSUE #123] Fix UnknownException when host config not exist
. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle
to make sure basic checks pass. Runmvn clean install -DskipITs
to make sure unit-test pass. Runmvn clean test-compile failsafe:integration-test
to make sure integration-test pass.