From 355abb2417de3dfe44503ac76e7f0a163435f6f6 Mon Sep 17 00:00:00 2001 From: liuhaolong Date: Sun, 8 Mar 2026 12:44:24 +0800 Subject: [PATCH 1/4] Add Spring RabbitMQ plugin --- .github/workflows/plugins-jdk17-test.0.yaml | 1 + .github/workflows/plugins-test.3.yaml | 1 + CHANGES.md | 1 + .../rabbitmq/RabbitMQConsumerInterceptor.java | 3 + .../apm-sdk-plugin/spring-plugins/pom.xml | 3 +- .../spring-rabbitmq-plugin/pom.xml | 29 +++++ .../SpringRabbitMQConsumerInterceptor.java | 85 +++++++++++++ ...SpringRabbitMQConsumerInstrumentation.java | 69 +++++++++++ .../src/main/resources/skywalking-plugin.def | 17 +++ ...RabbitMQSpringConsumerInterceptorTest.java | 111 +++++++++++++++++ .../service-agent/java-agent/Plugin-list.md | 3 + .../bin/startup.sh | 20 +++ .../config/expectedData.yaml | 73 +++++++++++ .../configuration.yml | 31 +++++ .../spring-rabbitmq-2.x-scenario/pom.xml | 100 +++++++++++++++ .../src/main/assembly/assembly.xml | 41 +++++++ .../testcase/spring/rabbitmq/Application.java | 30 +++++ .../rabbitmq/controller/CaseController.java | 116 ++++++++++++++++++ .../src/main/resources/application.yml | 28 +++++ .../src/main/resources/log4j2.xml | 31 +++++ .../support-version.list | 20 +++ .../bin/startup.sh | 20 +++ .../config/expectedData.yaml | 73 +++++++++++ .../configuration.yml | 31 +++++ .../spring-rabbitmq-3.x-4.x-scenario/pom.xml | 100 +++++++++++++++ .../src/main/assembly/assembly.xml | 41 +++++++ .../testcase/spring/rabbitmq/Application.java | 30 +++++ .../rabbitmq/controller/CaseController.java | 112 +++++++++++++++++ .../src/main/resources/application.yml | 28 +++++ .../src/main/resources/log4j2.xml | 31 +++++ .../support-version.list | 18 +++ 31 files changed, 1296 insertions(+), 1 deletion(-) create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/SpringRabbitMQConsumerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/define/SpringRabbitMQConsumerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/resources/skywalking-plugin.def create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/RabbitMQSpringConsumerInterceptorTest.java create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/bin/startup.sh create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/configuration.yml create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/Application.java create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/application.yml create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/log4j2.xml create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/support-version.list create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/bin/startup.sh create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/configuration.yml create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/Application.java create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/application.yml create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/log4j2.xml create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/support-version.list diff --git a/.github/workflows/plugins-jdk17-test.0.yaml b/.github/workflows/plugins-jdk17-test.0.yaml index 092fa2daae..6052ee5566 100644 --- a/.github/workflows/plugins-jdk17-test.0.yaml +++ b/.github/workflows/plugins-jdk17-test.0.yaml @@ -80,6 +80,7 @@ jobs: - jetty-11.x-scenario - jetty-10.x-scenario - spring-ai-1.x-scenario + - spring-rabbitmq-3.x-4.x-scenario steps: - uses: actions/checkout@v2 with: diff --git a/.github/workflows/plugins-test.3.yaml b/.github/workflows/plugins-test.3.yaml index 3d5880fd9f..b365fb56c6 100644 --- a/.github/workflows/plugins-test.3.yaml +++ b/.github/workflows/plugins-test.3.yaml @@ -96,6 +96,7 @@ jobs: - spring-kafka-1.3.x-scenario - spring-kafka-2.2.x-scenario - spring-kafka-2.3.x-scenario + - spring-rabbitmq-2.x-scenario - spring-scheduled-3.x-5.x-scenario - elasticjob-2.x-scenario - quartz-scheduler-2.x-scenario diff --git a/CHANGES.md b/CHANGES.md index 27e5c01fde..87fb6e5362 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ Release Notes. * Added support for Lettuce reactive Redis commands. * Add Spring AI 1.x plugin and GenAI layer. +* Add Spring RabbitMQ plugin. All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/249?closed=1) diff --git a/apm-sniffer/apm-sdk-plugin/rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/rabbitmq/RabbitMQConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/rabbitmq/RabbitMQConsumerInterceptor.java index 50240c9729..e80a0dfd1b 100644 --- a/apm-sniffer/apm-sdk-plugin/rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/rabbitmq/RabbitMQConsumerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/rabbitmq/RabbitMQConsumerInterceptor.java @@ -29,6 +29,9 @@ public class RabbitMQConsumerInterceptor implements InstanceMethodsAroundInterce @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { + if (Thread.currentThread().getName().toLowerCase().contains("springframework")) { + return; + } Consumer consumer = (Consumer) allArguments[6]; allArguments[6] = new TracerConsumer(consumer, (String) objInst.getSkyWalkingDynamicField()); } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml index 5a307810b3..4326ec7354 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml @@ -46,10 +46,11 @@ spring-webflux-6.x-webclient-plugin resttemplate-commons spring-ai-1.x-plugin + spring-rabbitmq-plugin pom - apm-sdk-plugin + spring-plugins http://maven.apache.org diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/pom.xml new file mode 100644 index 0000000000..3f61a88960 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + + org.apache.skywalking + spring-plugins + 9.7.0-SNAPSHOT + + + apm-spring-rabbitmq-plugin + apm-spring-rabbitmq-plugin + jar + + + 2.2.1.RELEASE + + + + + org.springframework.amqp + spring-rabbit + ${spring-rabbit.version} + provided + + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/SpringRabbitMQConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/SpringRabbitMQConsumerInterceptor.java new file mode 100644 index 0000000000..0333ee554c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/SpringRabbitMQConsumerInterceptor.java @@ -0,0 +1,85 @@ +/* + * 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.spring.rabbitmq; + +import java.lang.reflect.Method; +import java.util.Map; + +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 org.springframework.amqp.core.Message; +import org.springframework.amqp.core.MessageProperties; + +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Connection; + +public class SpringRabbitMQConsumerInterceptor implements InstanceMethodsAroundInterceptor { + public static final String OPERATE_NAME_PREFIX = "RabbitMQ/"; + public static final String CONSUMER_OPERATE_NAME_SUFFIX = "/Consumer"; + + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + Channel channel = (Channel) allArguments[0]; + Message message = (Message) allArguments[1]; + MessageProperties messageProperties = message.getMessageProperties(); + Map headers = messageProperties.getHeaders(); + ContextCarrier contextCarrier = new ContextCarrier(); + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + Object value = headers.get(next.getHeadKey()); + if (value != null) { + next.setHeadValue(value.toString()); + } + } + String operationName = OPERATE_NAME_PREFIX + "Topic/" + messageProperties.getReceivedExchange() + + "Queue/" + messageProperties.getReceivedRoutingKey() + CONSUMER_OPERATE_NAME_SUFFIX; + AbstractSpan activeSpan = ContextManager.createEntrySpan(operationName, contextCarrier); + Connection connection = channel.getConnection(); + String serverUrl = connection.getAddress().getHostAddress() + ":" + connection.getPort(); + Tags.MQ_BROKER.set(activeSpan, serverUrl); + Tags.MQ_TOPIC.set(activeSpan, messageProperties.getReceivedExchange()); + Tags.MQ_QUEUE.set(activeSpan, messageProperties.getReceivedRoutingKey()); + activeSpan.setComponent(ComponentsDefine.RABBITMQ_CONSUMER); + activeSpan.setPeer(serverUrl); + SpanLayer.asMQ(activeSpan); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override + public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/define/SpringRabbitMQConsumerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/define/SpringRabbitMQConsumerInstrumentation.java new file mode 100644 index 0000000000..d01c8cf328 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/define/SpringRabbitMQConsumerInstrumentation.java @@ -0,0 +1,69 @@ +/* + * 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.spring.rabbitmq.define; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.DeclaredInstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +public class SpringRabbitMQConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + public static final String ENHANCE_CLASS = "org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer"; + public static final String ENHANCE_METHOD = "executeListener"; + public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.rabbitmq.SpringRabbitMQConsumerInterceptor"; + + @Override + public ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new DeclaredInstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override + public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override + protected ClassMatch enhanceClass() { + return NameMatch.byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 0000000000..94d87de414 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,17 @@ +# 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. + +spring-rabbitmq=org.apache.skywalking.apm.plugin.spring.rabbitmq.define.SpringRabbitMQConsumerInstrumentation \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/RabbitMQSpringConsumerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/RabbitMQSpringConsumerInterceptorTest.java new file mode 100644 index 0000000000..308f97f54f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/src/test/java/org/apache/skywalking/apm/plugin/spring/rabbitmq/RabbitMQSpringConsumerInterceptorTest.java @@ -0,0 +1,111 @@ +/* + * 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.spring.rabbitmq; + +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.net.InetAddress; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.skywalking.apm.agent.core.context.SW8CarrierItem; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.core.MessageProperties; + +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Connection; + +@RunWith(TracingSegmentRunner.class) +public class RabbitMQSpringConsumerInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + private SpringRabbitMQConsumerInterceptor rabbitMQConsumerInterceptor; + + @Mock + private EnhancedInstance enhancedInstance; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Before + public void setUp() throws Exception { + rabbitMQConsumerInterceptor = new SpringRabbitMQConsumerInterceptor(); + } + + @Test + public void testRabbitMQConsumerInterceptorWithNilHeaders() throws Throwable { + Object[] args = prepareMockData(false); + rabbitMQConsumerInterceptor.beforeMethod(enhancedInstance, null, args, new Class[0], null); + rabbitMQConsumerInterceptor.afterMethod(enhancedInstance, null, args, new Class[0], null); + List traceSegments = segmentStorage.getTraceSegments(); + Assert.assertThat(traceSegments.size(), is(1)); + } + + @Test + public void testRabbitMQConsumerInterceptor() throws Throwable { + Object[] args = prepareMockData(true); + rabbitMQConsumerInterceptor.beforeMethod(enhancedInstance, null, args, new Class[0], null); + rabbitMQConsumerInterceptor.afterMethod(enhancedInstance, null, args, new Class[0], null); + List traceSegments = segmentStorage.getTraceSegments(); + Assert.assertThat(traceSegments.size(), is(1)); + } + + private Object[] prepareMockData(boolean withHeaders) throws Exception { + Channel channel = mock(Channel.class); + Connection connection = mock(Connection.class); + InetAddress address = mock(InetAddress.class); + Message message = mock(Message.class); + MessageProperties messageProperties = mock(MessageProperties.class); + + when(channel.getConnection()).thenReturn(connection); + when(connection.getAddress()).thenReturn(address); + when(address.getHostAddress()).thenReturn("127.0.0.1"); + when(connection.getPort()).thenReturn(5672); + when(message.getMessageProperties()).thenReturn(messageProperties); + when(messageProperties.getReceivedExchange()).thenReturn("test-exchange"); + when(messageProperties.getReceivedRoutingKey()).thenReturn("test-routing-key"); + + if (withHeaders) { + Map headers = new HashMap<>(); + headers.put(SW8CarrierItem.HEADER_NAME, + "1-My40LjU=-MS4yLjM=-3-c2VydmljZQ==-aW5zdGFuY2U=-L2FwcA==-MTI3LjAuMC4xOjgwODA="); + when(messageProperties.getHeader(SW8CarrierItem.HEADER_NAME)) + .thenReturn(headers.get(SW8CarrierItem.HEADER_NAME)); + } + + return new Object[] {channel, message}; + } +} diff --git a/docs/en/setup/service-agent/java-agent/Plugin-list.md b/docs/en/setup/service-agent/java-agent/Plugin-list.md index 49d1cb9c8e..db55f7d17b 100644 --- a/docs/en/setup/service-agent/java-agent/Plugin-list.md +++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md @@ -114,6 +114,9 @@ - spring-core-patch - spring-kafka-1.x - spring-kafka-2.x +- spring-rabbit-2.x +- spring-rabbit-3.x +- spring-rabbit-4.x - spring-mvc-annotation - spring-mvc-annotation-3.x - spring-mvc-annotation-4.x diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/bin/startup.sh b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/bin/startup.sh new file mode 100644 index 0000000000..bda43c219b --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/bin/startup.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# 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. + +home="$(cd "$(dirname $0)"; pwd)" + +java -Dspring.rabbitmq.host=${RABBITMQ_HOST} -jar ${agent_opts} ${home}/../libs/spring-rabbitmq-2.x-scenario.jar & diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/config/expectedData.yaml new file mode 100644 index 0000000000..9fcfd25aa7 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/config/expectedData.yaml @@ -0,0 +1,73 @@ +# 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. +segmentItems: +- serviceName: spring-rabbitmq-2.x-scenario + segmentSize: gt 2 + segments: + - segmentId: not null + spans: + - operationName: RabbitMQ/Topic/Queue/test/Consumer + parentSpanId: -1 + spanId: 0 + spanLayer: MQ + startTime: nq 0 + endTime: nq 0 + componentId: 53 + isError: false + spanType: Entry + peer: not blank + tags: + - {key: mq.broker, value: not blank} + - {key: mq.topic, value: ''} + - {key: mq.queue, value: test} + - {key: transmission.latency, value: ge 0} + refs: + - {parentEndpoint: GET:/spring-rabbitmq-2.x-scenario/case/rabbitmq, networkAddress: not null, + refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not + null, parentService: spring-rabbitmq-2.x-scenario, traceId: not null} + skipAnalysis: 'false' + - segmentId: not null + spans: + - operationName: RabbitMQ/Topic/Queue/test/Producer + parentSpanId: 0 + spanId: 1 + spanLayer: MQ + startTime: nq 0 + endTime: nq 0 + componentId: 52 + isError: false + spanType: Exit + peer: not blank + tags: + - {key: mq.broker, value: not blank} + - {key: mq.queue, value: test} + - {key: mq.topic, value: ''} + skipAnalysis: 'false' + - operationName: GET:/spring-rabbitmq-2.x-scenario/case/rabbitmq + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/spring-rabbitmq-2.x-scenario/case/rabbitmq'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + skipAnalysis: 'false' diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/configuration.yml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/configuration.yml new file mode 100644 index 0000000000..4b5f50935a --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/configuration.yml @@ -0,0 +1,31 @@ +# 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. +type: jvm +entryService: http://localhost:8080/spring-rabbitmq-2.x-scenario/case/rabbitmq +healthCheck: http://localhost:8080/spring-rabbitmq-2.x-scenario/case/healthcheck +startScript: ./bin/startup.sh +environment: + - RABBITMQ_HOST=rabbitmq-server +dependencies: + rabbitmq-server: + image: rabbitmq:3.8.18 + hostname: rabbitmq-server + expose: + - 5672 + - 15672 + environment: + - RABBITMQ_DEFAULT_PASS=admin + - RABBITMQ_DEFAULT_USER=admin + - RABBITMQ_DEFAULT_VHOST=/ diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml new file mode 100644 index 0000000000..f80be539d1 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + + org.apache.skywalking + spring-rabbitmq-2.x-scenario + 1.0-SNAPSHOT + + + UTF-8 + 1.8 + 3.8.1 + 1.5.0.RELEASE + ${test.framework.version} + 2.8.1 + + + + + org.springframework.boot + spring-boot-starter-amqp + ${test.framework.version} + + + + org.springframework.boot + spring-boot-starter + ${test.framework.version} + + + spring-boot-starter-logging + org.springframework.boot + + + + + org.springframework.boot + spring-boot-starter-web + ${test.framework.version} + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + + + spring-rabbitmq-2.x-scenario + + + org.springframework.boot + spring-boot-maven-plugin + 1.5.9.RELEASE + + + + repackage + + + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/assembly/assembly.xml new file mode 100644 index 0000000000..a4e443d949 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/spring-rabbitmq-2.x-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/Application.java b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/Application.java new file mode 100644 index 0000000000..9001ed22a9 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/Application.java @@ -0,0 +1,30 @@ +/* + * 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.testcase.spring.rabbitmq; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java new file mode 100644 index 0000000000..269f8436a7 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java @@ -0,0 +1,116 @@ +/* + * 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.testcase.spring.rabbitmq.controller; + +import com.rabbitmq.client.AMQP; +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Connection; +import com.rabbitmq.client.ConnectionFactory; + +import java.nio.charset.StandardCharsets; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/case") +@PropertySource("classpath:application.yml") +public class CaseController { + + private static final Logger LOGGER = LogManager.getLogger(CaseController.class); + + private static final String USERNAME = "admin"; + + private static final String PASSWORD = "admin"; + + @Value(value = "${spring.rabbitmq.host:127.0.0.1}") + private String brokerUrl; + + private static final int PORT = 5672; + + private static final String QUEUE_NAME = "test"; + + private static final String MESSAGE = "rabbitmq-testcase"; + + @Autowired + private RabbitTemplate rabbitTemplate; + + @RequestMapping("/rabbitmq") + @ResponseBody + public String send() { + LOGGER.info("Message being published -------------->" + MESSAGE); + rabbitTemplate.convertAndSend(QUEUE_NAME, MESSAGE); + LOGGER.info("Message has been published-------------->" + MESSAGE); + return "Success"; + } + + @RabbitListener(queues = QUEUE_NAME) + public void consumer(String message) { + LOGGER.info("Message Consumer received-------------->" + message); + } + + @RequestMapping("/healthcheck") + public String healthCheck() throws Exception { + Channel channel = null; + Connection connection = null; + + try { + ConnectionFactory factory = new ConnectionFactory(); + LOGGER.info("Using brokerUrl = " + brokerUrl); + factory.setHost(brokerUrl); + factory.setPort(PORT); + factory.setUsername(USERNAME); + factory.setPassword(PASSWORD); + + connection = factory.newConnection(); + + channel = connection.createChannel(); + channel.queueDeclare(QUEUE_NAME, false, false, false, null); + LOGGER.info("Completed Health Check. Able to connect to RabbitMQ and create queue-------------->"); + } catch (Exception ex) { + LOGGER.error(ex.toString()); + throw ex; + } finally { + if (channel != null) { + try { + channel.close(); + } catch (Exception e) { + // ignore + } + } + if (connection != null) { + try { + connection.close(); + } catch (Exception e) { + // ignore + } + } + } + return "Success"; + } +} diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/application.yml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/application.yml new file mode 100644 index 0000000000..a38195e304 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/application.yml @@ -0,0 +1,28 @@ +# +# 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. +# +# +server: + port: 8080 + servlet: + context-path: /spring-rabbitmq-2.x-scenario + +spring: + rabbitmq: + host: 127.0.0.1 + port: 5672 + username: admin + password: admin diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..565fda00e0 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/support-version.list b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/support-version.list new file mode 100644 index 0000000000..5d08d9eb7e --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/support-version.list @@ -0,0 +1,20 @@ +# 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. + +2.0.0.RELEASE +2.1.0.RELEASE +2.2.0.RELEASE +2.4.0 \ No newline at end of file diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/bin/startup.sh b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/bin/startup.sh new file mode 100644 index 0000000000..202ef88cc0 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/bin/startup.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# 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. + +home="$(cd "$(dirname $0)"; pwd)" + +java -Dspring.rabbitmq.host=${RABBITMQ_HOST} -jar ${agent_opts} ${home}/../libs/spring-rabbitmq-3.x-4.x-scenario.jar & diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/config/expectedData.yaml new file mode 100644 index 0000000000..1dd657b614 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/config/expectedData.yaml @@ -0,0 +1,73 @@ +# 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. +segmentItems: +- serviceName: spring-rabbitmq-3.x-4.x-scenario + segmentSize: gt 2 + segments: + - segmentId: not null + spans: + - operationName: RabbitMQ/Topic/Queue/test/Consumer + parentSpanId: -1 + spanId: 0 + spanLayer: MQ + startTime: nq 0 + endTime: nq 0 + componentId: 53 + isError: false + spanType: Entry + peer: not blank + tags: + - {key: mq.broker, value: not blank} + - {key: mq.topic, value: ''} + - {key: mq.queue, value: test} + - {key: transmission.latency, value: ge 0} + refs: + - {parentEndpoint: GET:/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq, networkAddress: not null, + refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not + null, parentService: spring-rabbitmq-3.x-4.x-scenario, traceId: not null} + skipAnalysis: 'false' + - segmentId: not null + spans: + - operationName: RabbitMQ/Topic/Queue/test/Producer + parentSpanId: 0 + spanId: 1 + spanLayer: MQ + startTime: nq 0 + endTime: nq 0 + componentId: 52 + isError: false + spanType: Exit + peer: not blank + tags: + - {key: mq.broker, value: not blank} + - {key: mq.queue, value: test} + - {key: mq.topic, value: ''} + skipAnalysis: 'false' + - operationName: GET:/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + isError: false + spanType: Entry + peer: '' + tags: + - {key: url, value: 'http://localhost:8080/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} + skipAnalysis: 'false' diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/configuration.yml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/configuration.yml new file mode 100644 index 0000000000..66dc3bad9d --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/configuration.yml @@ -0,0 +1,31 @@ +# 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. +type: jvm +entryService: http://localhost:8080/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq +healthCheck: http://localhost:8080/spring-rabbitmq-3.x-4.x-scenario/case/healthcheck +startScript: ./bin/startup.sh +environment: + - RABBITMQ_HOST=rabbitmq-server +dependencies: + rabbitmq-server: + image: rabbitmq:3.8.18 + hostname: rabbitmq-server + expose: + - 5672 + - 15672 + environment: + - RABBITMQ_DEFAULT_PASS=admin + - RABBITMQ_DEFAULT_USER=admin + - RABBITMQ_DEFAULT_VHOST=/ diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml new file mode 100644 index 0000000000..67e9891824 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + + org.apache.skywalking + spring-rabbitmq-3.x-4.x-scenario + 1.0-SNAPSHOT + + + UTF-8 + 17 + 3.8.1 + 3.0.0 + ${test.framework.version} + 2.19.0 + + + + + org.springframework.boot + spring-boot-starter-amqp + ${test.framework.version} + + + + org.springframework.boot + spring-boot-starter + ${test.framework.version} + + + spring-boot-starter-logging + org.springframework.boot + + + + + org.springframework.boot + spring-boot-starter-web + ${test.framework.version} + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + + + spring-rabbitmq-3.x-4.x-scenario + + + org.springframework.boot + spring-boot-maven-plugin + 1.5.9.RELEASE + + + + repackage + + + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/assembly/assembly.xml new file mode 100644 index 0000000000..e7c504dc07 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/spring-rabbitmq-3.x-4.x-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/Application.java b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/Application.java new file mode 100644 index 0000000000..9001ed22a9 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/Application.java @@ -0,0 +1,30 @@ +/* + * 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.testcase.spring.rabbitmq; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java new file mode 100644 index 0000000000..c3453ca6b4 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java @@ -0,0 +1,112 @@ +/* + * 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.testcase.spring.rabbitmq.controller; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Connection; +import com.rabbitmq.client.ConnectionFactory; + +@RestController +@RequestMapping("/case") +@PropertySource("classpath:application.yml") +public class CaseController { + + private static final Logger LOGGER = LogManager.getLogger(CaseController.class); + + private static final String USERNAME = "admin"; + + private static final String PASSWORD = "admin"; + + @Value(value = "${spring.rabbitmq.host:127.0.0.1}") + private String brokerUrl; + + private static final int PORT = 5672; + + private static final String QUEUE_NAME = "test"; + + private static final String MESSAGE = "rabbitmq-testcase"; + + @Autowired + private RabbitTemplate rabbitTemplate; + + @RequestMapping("/rabbitmq") + @ResponseBody + public String send() { + LOGGER.info("Message being published -------------->" + MESSAGE); + rabbitTemplate.convertAndSend(QUEUE_NAME, MESSAGE); + LOGGER.info("Message has been published-------------->" + MESSAGE); + return "Success"; + } + + @RabbitListener(queues = QUEUE_NAME) + public void consumer(String message) { + LOGGER.info("Message Consumer received-------------->" + message); + } + + @RequestMapping("/healthcheck") + public String healthCheck() throws Exception { + Channel channel = null; + Connection connection = null; + + try { + ConnectionFactory factory = new ConnectionFactory(); + LOGGER.info("Using brokerUrl = " + brokerUrl); + factory.setHost(brokerUrl); + factory.setPort(PORT); + factory.setUsername(USERNAME); + factory.setPassword(PASSWORD); + + connection = factory.newConnection(); + + channel = connection.createChannel(); + channel.queueDeclare(QUEUE_NAME, false, false, false, null); + LOGGER.info("Completed Health Check. Able to connect to RabbitMQ and create queue-------------->"); + } catch (Exception ex) { + LOGGER.error(ex.toString()); + throw ex; + } finally { + if (channel != null) { + try { + channel.close(); + } catch (Exception e) { + // ignore + } + } + if (connection != null) { + try { + connection.close(); + } catch (Exception e) { + // ignore + } + } + } + return "Success"; + } +} diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/application.yml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/application.yml new file mode 100644 index 0000000000..44d5f1a84b --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/application.yml @@ -0,0 +1,28 @@ +# +# 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. +# +# +server: + port: 8080 + servlet: + context-path: /spring-rabbitmq-3.x-4.x-scenario + +spring: + rabbitmq: + host: 127.0.0.1 + port: 5672 + username: admin + password: admin diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..565fda00e0 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/support-version.list b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/support-version.list new file mode 100644 index 0000000000..8c67d6f4a8 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/support-version.list @@ -0,0 +1,18 @@ +# 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. + +3.0.0 +4.0.0 \ No newline at end of file From 46c196c68a973c432bfcff15e2fac91a155f5f14 Mon Sep 17 00:00:00 2001 From: liuhaolong Date: Sun, 8 Mar 2026 13:49:41 +0800 Subject: [PATCH 2/4] Add Licensed Header --- .../spring-rabbitmq-plugin/pom.xml | 17 +++++++++++++++++ .../spring-rabbitmq-2.x-scenario/pom.xml | 17 +++++++++++++++++ .../spring-rabbitmq-3.x-4.x-scenario/pom.xml | 17 +++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/pom.xml index 3f61a88960..452fc79893 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-rabbitmq-plugin/pom.xml @@ -1,4 +1,21 @@ + diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml index f80be539d1..71cb4caeb2 100644 --- a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml @@ -1,4 +1,21 @@ + diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml index 67e9891824..123b10e68f 100644 --- a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml @@ -1,4 +1,21 @@ + From 23df581345ea30c74b07399b055b87ff1ccc4529 Mon Sep 17 00:00:00 2001 From: liuhaolong Date: Sun, 8 Mar 2026 14:19:42 +0800 Subject: [PATCH 3/4] Update spring rabbitmq test --- .../en/setup/service-agent/java-agent/Plugin-list.md | 4 +--- .../spring/rabbitmq/controller/CaseController.java | 12 ++++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/docs/en/setup/service-agent/java-agent/Plugin-list.md b/docs/en/setup/service-agent/java-agent/Plugin-list.md index db55f7d17b..3764ae9716 100644 --- a/docs/en/setup/service-agent/java-agent/Plugin-list.md +++ b/docs/en/setup/service-agent/java-agent/Plugin-list.md @@ -114,9 +114,7 @@ - spring-core-patch - spring-kafka-1.x - spring-kafka-2.x -- spring-rabbit-2.x -- spring-rabbit-3.x -- spring-rabbit-4.x +- spring-rabbitmq - spring-mvc-annotation - spring-mvc-annotation-3.x - spring-mvc-annotation-4.x diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java index 269f8436a7..c3453ca6b4 100644 --- a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java @@ -18,16 +18,8 @@ package org.apache.skywalking.apm.testcase.spring.rabbitmq.controller; -import com.rabbitmq.client.AMQP; -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Connection; -import com.rabbitmq.client.ConnectionFactory; - -import java.nio.charset.StandardCharsets; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; @@ -37,6 +29,10 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Connection; +import com.rabbitmq.client.ConnectionFactory; + @RestController @RequestMapping("/case") @PropertySource("classpath:application.yml") From 663704c60679d3e79522af144723a7b9ce381a05 Mon Sep 17 00:00:00 2001 From: liuhaolong Date: Tue, 10 Mar 2026 11:47:39 +0800 Subject: [PATCH 4/4] Update spring rabbitmq test --- .../bin/startup.sh | 2 +- .../config/expectedData.yaml | 46 ++++++++--------- .../configuration.yml | 2 + .../spring-rabbitmq-2.x-scenario/pom.xml | 2 +- .../rabbitmq/config/RabbitMqConfig.java | 32 ++++++++++++ .../rabbitmq/controller/CaseController.java | 51 ------------------- .../src/main/resources/application.yml | 3 +- .../bin/startup.sh | 2 +- .../config/expectedData.yaml | 46 ++++++++--------- .../configuration.yml | 2 + .../spring-rabbitmq-3.x-4.x-scenario/pom.xml | 2 +- .../rabbitmq/config/RabbitMqConfig.java | 32 ++++++++++++ .../rabbitmq/controller/CaseController.java | 51 ------------------- .../src/main/resources/application.yml | 3 +- 14 files changed, 122 insertions(+), 154 deletions(-) create mode 100644 test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/config/RabbitMqConfig.java create mode 100644 test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/config/RabbitMqConfig.java diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/bin/startup.sh b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/bin/startup.sh index bda43c219b..5a75b66754 100644 --- a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/bin/startup.sh @@ -17,4 +17,4 @@ home="$(cd "$(dirname $0)"; pwd)" -java -Dspring.rabbitmq.host=${RABBITMQ_HOST} -jar ${agent_opts} ${home}/../libs/spring-rabbitmq-2.x-scenario.jar & +java -Dspring.rabbitmq.host=${RABBITMQ_HOST:-rabbitmq-server} -jar ${agent_opts} ${home}/../libs/spring-rabbitmq-2.x-scenario.jar & diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/config/expectedData.yaml index 9fcfd25aa7..fee535115f 100644 --- a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/config/expectedData.yaml @@ -3,8 +3,8 @@ # 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 +# "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 # @@ -19,28 +19,21 @@ segmentItems: segments: - segmentId: not null spans: - - operationName: RabbitMQ/Topic/Queue/test/Consumer + - operationName: GET:/spring-rabbitmq-2.x-scenario/case/rabbitmq parentSpanId: -1 spanId: 0 - spanLayer: MQ + spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 53 + componentId: 1 isError: false spanType: Entry - peer: not blank + peer: '' tags: - - {key: mq.broker, value: not blank} - - {key: mq.topic, value: ''} - - {key: mq.queue, value: test} - - {key: transmission.latency, value: ge 0} - refs: - - {parentEndpoint: GET:/spring-rabbitmq-2.x-scenario/case/rabbitmq, networkAddress: not null, - refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not - null, parentService: spring-rabbitmq-2.x-scenario, traceId: not null} + - {key: url, value: 'http://localhost:8080/spring-rabbitmq-2.x-scenario/case/rabbitmq'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} skipAnalysis: 'false' - - segmentId: not null - spans: - operationName: RabbitMQ/Topic/Queue/test/Producer parentSpanId: 0 spanId: 1 @@ -56,18 +49,25 @@ segmentItems: - {key: mq.queue, value: test} - {key: mq.topic, value: ''} skipAnalysis: 'false' - - operationName: GET:/spring-rabbitmq-2.x-scenario/case/rabbitmq + - segmentId: not null + spans: + - operationName: RabbitMQ/Topic/Queue/test/Consumer parentSpanId: -1 spanId: 0 - spanLayer: Http + spanLayer: MQ startTime: nq 0 endTime: nq 0 - componentId: 1 + componentId: 53 isError: false spanType: Entry - peer: '' + peer: not blank tags: - - {key: url, value: 'http://localhost:8080/spring-rabbitmq-2.x-scenario/case/rabbitmq'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} + - {key: transmission.latency, value: ge 0} + - {key: mq.broker, value: not blank} + - {key: mq.topic, value: ''} + - {key: mq.queue, value: test} + refs: + - {parentEndpoint: GET:/spring-rabbitmq-2.x-scenario/case/rabbitmq, networkAddress: not null, + refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not + null, parentService: spring-rabbitmq-2.x-scenario, traceId: not null} skipAnalysis: 'false' diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/configuration.yml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/configuration.yml index 4b5f50935a..a14199f3c3 100644 --- a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/configuration.yml +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/configuration.yml @@ -18,6 +18,8 @@ healthCheck: http://localhost:8080/spring-rabbitmq-2.x-scenario/case/healthcheck startScript: ./bin/startup.sh environment: - RABBITMQ_HOST=rabbitmq-server +depends_on: + - rabbitmq-server dependencies: rabbitmq-server: image: rabbitmq:3.8.18 diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml index 71cb4caeb2..1e2c7e913b 100644 --- a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/pom.xml @@ -75,7 +75,7 @@ org.springframework.boot spring-boot-maven-plugin - 1.5.9.RELEASE + ${test.framework.version} diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/config/RabbitMqConfig.java b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/config/RabbitMqConfig.java new file mode 100644 index 0000000000..74c401f9e2 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/config/RabbitMqConfig.java @@ -0,0 +1,32 @@ +/* + * 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.testcase.spring.rabbitmq.config; + +import org.springframework.amqp.core.Queue; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RabbitMqConfig { + + @Bean + public Queue testQueue() { + return new Queue("test", false); + } +} diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java index c3453ca6b4..ca2a9d800d 100644 --- a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java @@ -23,32 +23,16 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.PropertySource; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Connection; -import com.rabbitmq.client.ConnectionFactory; - @RestController @RequestMapping("/case") -@PropertySource("classpath:application.yml") public class CaseController { private static final Logger LOGGER = LogManager.getLogger(CaseController.class); - private static final String USERNAME = "admin"; - - private static final String PASSWORD = "admin"; - - @Value(value = "${spring.rabbitmq.host:127.0.0.1}") - private String brokerUrl; - - private static final int PORT = 5672; - private static final String QUEUE_NAME = "test"; private static final String MESSAGE = "rabbitmq-testcase"; @@ -72,41 +56,6 @@ public void consumer(String message) { @RequestMapping("/healthcheck") public String healthCheck() throws Exception { - Channel channel = null; - Connection connection = null; - - try { - ConnectionFactory factory = new ConnectionFactory(); - LOGGER.info("Using brokerUrl = " + brokerUrl); - factory.setHost(brokerUrl); - factory.setPort(PORT); - factory.setUsername(USERNAME); - factory.setPassword(PASSWORD); - - connection = factory.newConnection(); - - channel = connection.createChannel(); - channel.queueDeclare(QUEUE_NAME, false, false, false, null); - LOGGER.info("Completed Health Check. Able to connect to RabbitMQ and create queue-------------->"); - } catch (Exception ex) { - LOGGER.error(ex.toString()); - throw ex; - } finally { - if (channel != null) { - try { - channel.close(); - } catch (Exception e) { - // ignore - } - } - if (connection != null) { - try { - connection.close(); - } catch (Exception e) { - // ignore - } - } - } return "Success"; } } diff --git a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/application.yml b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/application.yml index a38195e304..7310f8a17e 100644 --- a/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/application.yml +++ b/test/plugin/scenarios/spring-rabbitmq-2.x-scenario/src/main/resources/application.yml @@ -22,7 +22,8 @@ server: spring: rabbitmq: - host: 127.0.0.1 + host: ${RABBITMQ_HOST:127.0.0.1} port: 5672 username: admin password: admin + virtual-host: / diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/bin/startup.sh b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/bin/startup.sh index 202ef88cc0..f48486c177 100644 --- a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/bin/startup.sh +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/bin/startup.sh @@ -17,4 +17,4 @@ home="$(cd "$(dirname $0)"; pwd)" -java -Dspring.rabbitmq.host=${RABBITMQ_HOST} -jar ${agent_opts} ${home}/../libs/spring-rabbitmq-3.x-4.x-scenario.jar & +java -Dspring.rabbitmq.host=${RABBITMQ_HOST:-rabbitmq-server} -jar ${agent_opts} ${home}/../libs/spring-rabbitmq-3.x-4.x-scenario.jar & diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/config/expectedData.yaml index 1dd657b614..901e8f3d6f 100644 --- a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/config/expectedData.yaml +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/config/expectedData.yaml @@ -3,8 +3,8 @@ # 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 +# "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 # @@ -19,28 +19,21 @@ segmentItems: segments: - segmentId: not null spans: - - operationName: RabbitMQ/Topic/Queue/test/Consumer + - operationName: GET:/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq parentSpanId: -1 spanId: 0 - spanLayer: MQ + spanLayer: Http startTime: nq 0 endTime: nq 0 - componentId: 53 + componentId: 1 isError: false spanType: Entry - peer: not blank + peer: '' tags: - - {key: mq.broker, value: not blank} - - {key: mq.topic, value: ''} - - {key: mq.queue, value: test} - - {key: transmission.latency, value: ge 0} - refs: - - {parentEndpoint: GET:/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq, networkAddress: not null, - refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not - null, parentService: spring-rabbitmq-3.x-4.x-scenario, traceId: not null} + - {key: url, value: 'http://localhost:8080/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq'} + - {key: http.method, value: GET} + - {key: http.status_code, value: '200'} skipAnalysis: 'false' - - segmentId: not null - spans: - operationName: RabbitMQ/Topic/Queue/test/Producer parentSpanId: 0 spanId: 1 @@ -56,18 +49,25 @@ segmentItems: - {key: mq.queue, value: test} - {key: mq.topic, value: ''} skipAnalysis: 'false' - - operationName: GET:/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq + - segmentId: not null + spans: + - operationName: RabbitMQ/Topic/Queue/test/Consumer parentSpanId: -1 spanId: 0 - spanLayer: Http + spanLayer: MQ startTime: nq 0 endTime: nq 0 - componentId: 1 + componentId: 53 isError: false spanType: Entry - peer: '' + peer: not blank tags: - - {key: url, value: 'http://localhost:8080/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq'} - - {key: http.method, value: GET} - - {key: http.status_code, value: '200'} + - {key: transmission.latency, value: ge 0} + - {key: mq.broker, value: not blank} + - {key: mq.topic, value: ''} + - {key: mq.queue, value: test} + refs: + - {parentEndpoint: GET:/spring-rabbitmq-3.x-4.x-scenario/case/rabbitmq, networkAddress: not null, + refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: not null, parentServiceInstance: not + null, parentService: spring-rabbitmq-3.x-4.x-scenario, traceId: not null} skipAnalysis: 'false' diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/configuration.yml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/configuration.yml index 66dc3bad9d..e19c7a64b5 100644 --- a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/configuration.yml +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/configuration.yml @@ -18,6 +18,8 @@ healthCheck: http://localhost:8080/spring-rabbitmq-3.x-4.x-scenario/case/healthc startScript: ./bin/startup.sh environment: - RABBITMQ_HOST=rabbitmq-server +depends_on: + - rabbitmq-server dependencies: rabbitmq-server: image: rabbitmq:3.8.18 diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml index 123b10e68f..c301b0ada3 100644 --- a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/pom.xml @@ -75,7 +75,7 @@ org.springframework.boot spring-boot-maven-plugin - 1.5.9.RELEASE + ${test.framework.version} diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/config/RabbitMqConfig.java b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/config/RabbitMqConfig.java new file mode 100644 index 0000000000..74c401f9e2 --- /dev/null +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/config/RabbitMqConfig.java @@ -0,0 +1,32 @@ +/* + * 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.testcase.spring.rabbitmq.config; + +import org.springframework.amqp.core.Queue; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RabbitMqConfig { + + @Bean + public Queue testQueue() { + return new Queue("test", false); + } +} diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java index c3453ca6b4..ca2a9d800d 100644 --- a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/spring/rabbitmq/controller/CaseController.java @@ -23,32 +23,16 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.PropertySource; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Connection; -import com.rabbitmq.client.ConnectionFactory; - @RestController @RequestMapping("/case") -@PropertySource("classpath:application.yml") public class CaseController { private static final Logger LOGGER = LogManager.getLogger(CaseController.class); - private static final String USERNAME = "admin"; - - private static final String PASSWORD = "admin"; - - @Value(value = "${spring.rabbitmq.host:127.0.0.1}") - private String brokerUrl; - - private static final int PORT = 5672; - private static final String QUEUE_NAME = "test"; private static final String MESSAGE = "rabbitmq-testcase"; @@ -72,41 +56,6 @@ public void consumer(String message) { @RequestMapping("/healthcheck") public String healthCheck() throws Exception { - Channel channel = null; - Connection connection = null; - - try { - ConnectionFactory factory = new ConnectionFactory(); - LOGGER.info("Using brokerUrl = " + brokerUrl); - factory.setHost(brokerUrl); - factory.setPort(PORT); - factory.setUsername(USERNAME); - factory.setPassword(PASSWORD); - - connection = factory.newConnection(); - - channel = connection.createChannel(); - channel.queueDeclare(QUEUE_NAME, false, false, false, null); - LOGGER.info("Completed Health Check. Able to connect to RabbitMQ and create queue-------------->"); - } catch (Exception ex) { - LOGGER.error(ex.toString()); - throw ex; - } finally { - if (channel != null) { - try { - channel.close(); - } catch (Exception e) { - // ignore - } - } - if (connection != null) { - try { - connection.close(); - } catch (Exception e) { - // ignore - } - } - } return "Success"; } } diff --git a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/application.yml b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/application.yml index 44d5f1a84b..95dabedad1 100644 --- a/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/application.yml +++ b/test/plugin/scenarios/spring-rabbitmq-3.x-4.x-scenario/src/main/resources/application.yml @@ -22,7 +22,8 @@ server: spring: rabbitmq: - host: 127.0.0.1 + host: ${RABBITMQ_HOST:127.0.0.1} port: 5672 username: admin password: admin + virtual-host: /