vongosling commented on a change in pull request #324:
URL: https://github.com/apache/rocketmq-spring/pull/324#discussion_r539793179
##########
File path: pom.xml
##########
@@ -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>
Review comment:
why did you add prefix placeholder before the root directory /src?
##########
File path:
rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/AtomicLongMetricExtension.java
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.EConsumerMode;
+import org.apache.rocketmq.spring.metric.MetricExtension;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class AtomicLongMetricExtension implements MetricExtension {
+
+ private final Map<String, AtomicLong> producerMessageCountMap = new
ConcurrentHashMap<>();
+ private final Map<String, AtomicLong> consumerMessageCountMap = new
ConcurrentHashMap<>();
+
+ @Override
+ public void addProducerMessageCount(String topic, int count) {
+ AtomicLong atomicLong = producerMessageCountMap.computeIfAbsent(topic,
t -> new AtomicLong());
+ System.out.printf("The count of producer messages for %s is %d.%n",
topic, atomicLong.addAndGet(count));
Review comment:
It's not best practice to print info in the console. you could make a
switch and log it. And do not make too many copies of this class in the
different submodule.
##########
File path:
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/metric/EConsumerMode.java
##########
@@ -0,0 +1,29 @@
+/*
+ * 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 enum EConsumerMode {
Review comment:
Please do not make an enum here. you could use the existing class.
##########
File path:
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/metric/MetricExtension.java
##########
@@ -0,0 +1,38 @@
+/*
+ * 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 {
+
+ /**
+ * Add current count of message from the producer.
+ *
+ * @param topic topic name
+ * @param count count of message
+ */
+ void addProducerMessageCount(String topic, int count);
Review comment:
int or long should be consistent.
##########
File path:
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/DefaultLitePullConsumerWithTopic.java
##########
@@ -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 {
Review comment:
DefaultLitePullConsumerWithTopic is not a rational name here.
##########
File path:
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQTemplate.java
##########
@@ -236,6 +238,7 @@ public void setAsyncSenderExecutor(ExecutorService
asyncSenderExecutor) {
if (delayLevel > 0) {
rocketMsg.setDelayTimeLevel(delayLevel);
}
+
MetricExtensionProvider.addProducerMessageCount(rocketMsg.getTopic(), 1);
Review comment:
I suggest you use an atomic data structure instead of plus 1 here:-)
##########
File path:
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/metric/MetricExtensionProvider.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ServiceLoader;
+
+public class MetricExtensionProvider {
Review comment:
Do not make class by yourself. I strongly recommend you use a similar
service loader mode in RocketMQ. It has many backoff strategies and verified in
the production environment.
##########
File path:
rocketmq-spring-boot/src/test/java/org/apache/rocketmq/spring/metric/MetricExtensionTest.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class MetricExtensionTest implements MetricExtension {
+
+ private static String TOPIC;
+ private static int COUNT;
+ private static EConsumerMode CONSUMER_MODE;
+
+ @Override
+ public void addProducerMessageCount(String topic, int count) {
+ TOPIC = topic;
+ COUNT = count;
+ }
+
+ @Override
+ public void addConsumerMessageCount(String topic, int count, EConsumerMode
consumerMode) {
+ TOPIC = topic;
+ COUNT = count;
+ CONSUMER_MODE = consumerMode;
+ }
+
+ @Test
+ public void testAddProducerMessageCount() {
+ MetricExtensionProvider.addProducerMessageCount("topic1", 111);
Review comment:
It could be helpful for your code convincible if you could make more
corner cases, such as have you simulated the count of failures?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]