You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/04/19 14:59:03 UTC

[GitHub] [skywalking] codelipenghui commented on a change in pull request #6774: feat: add enhance pulsar MessageListener instance

codelipenghui commented on a change in pull request #6774:
URL: https://github.com/apache/skywalking/pull/6774#discussion_r615924647



##########
File path: test/plugin/scenarios/pulsar-scenario/src/main/java/test/apache/skywalking/apm/testcase/pulsar/controller/CaseController.java
##########
@@ -51,38 +51,37 @@ public String pulsarCase() throws PulsarClientException, InterruptedException {
 
         String topic = "test";
 
+        CountDownLatch latch = new CountDownLatch(1);
+
         PulsarClient pulsarClient = PulsarClient.builder().serviceUrl(PULSAR_DOMAIN + serviceUrl).build();
 
         Producer<byte[]> producer = pulsarClient.newProducer().topic(topic).create();
 
-        Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topic).subscriptionName("test").subscribe();
+        Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topic)

Review comment:
       I noticed you are replacing the old one(based on the receive method) with the message listener one. We should cover all of these two cases in the test. Could you please add a new consumer or add a new test for this case. I think you can add a new consumer with a different subscription name which will get the same messages from the topic.

##########
File path: apm-sniffer/apm-sdk-plugin/pulsar-plugin/src/main/java/org/apache/skywalking/apm/plugin/pulsar/PulsarConsumerListenerInterceptor.java
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.skywalking.apm.plugin.pulsar;
+
+import org.apache.pulsar.client.api.Message;
+import org.apache.skywalking.apm.agent.core.context.CarrierItem;
+import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.context.tag.Tags;
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
+import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+
+import java.lang.reflect.Method;
+
+/**
+ * Interceptor for pulsar consumer message listener enhanced instance
+ * <p>
+ * Here is the intercept process steps:
+ *
+ * <pre>
+ *  1. Get @{@link ContextCarrier} from message
+ *  2. Create a local span when call <code>received</code> method
+ *  3. Extract trace information from context carrier
+ *  4. Stop the local span when <code>received</code> method finished.
+ * </pre>
+ */
+public class PulsarConsumerListenerInterceptor implements InstanceMethodsAroundInterceptor {
+
+    public static final String CONSUMER_OPERATE_NAME = "Pulsar/Consumer/MessageListener";

Review comment:
       Shall we need to introduce a new operation name? The message listener just a way to consume messages, for the tracing context, we just need to know the consumer got the message.
   
   And, the message listener can't work together with the receive() method, so I think we can use the existing operation name.




-- 
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:
users@infra.apache.org