From c3edff870cc780f8447be97e4ee24e0d3c2dd54d Mon Sep 17 00:00:00 2001 From: daizhenyu <1449308021@qq.com> Date: Fri, 27 Oct 2023 23:37:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E9=87=8F=E6=A0=87=E7=AD=BE=E9=80=8F?= =?UTF-8?q?=E4=BC=A0=E6=8F=92=E4=BB=B6=E9=9B=86=E6=88=90=E6=B5=8B=E8=AF=95?= =?UTF-8?q?demo=EF=BC=9Atomcat=20demo=E3=80=81jetty=20demo=E3=80=81jdkhttp?= =?UTF-8?q?=20demo=E3=80=81httpclientv3=20demo=E3=80=81httpclientv4=20demo?= =?UTF-8?q?=E3=80=81midware-common=20demo=E3=80=81rocketmq-consumer-demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../httpclientv3-demo/pom.xml | 40 +++++++++ .../httpclientv3/HttpClientApplication.java | 38 +++++++++ .../controller/HttpClientV3Controller.java | 63 +++++++++++++++ .../src/main/resources/application.properties | 2 + .../httpclientv4-demo/pom.xml | 40 +++++++++ .../httpclientv4/HttpClientApplication.java | 38 +++++++++ .../controller/HttpClientV4Controller.java | 67 +++++++++++++++ .../src/main/resources/application.properties | 2 + .../jdkhttp-demo/pom.xml | 39 +++++++++ .../jdkhttp/JdkHttpApplication.java | 38 +++++++++ .../jdkhttp/controller/JdkHttpController.java | 65 +++++++++++++++ .../src/main/resources/application.properties | 3 + .../tag-transmission-test/jetty-demo/pom.xml | 52 ++++++++++++ .../jettyserver/HttpJettyApplication.java | 38 +++++++++ .../controller/ServerController.java | 48 +++++++++++ .../src/main/resources/application.properties | 2 + .../midware-common-demo/pom.xml | 19 +++++ .../midware/common/MessageConstant.java | 78 ++++++++++++++++++ .../rocketmq-consumer-demo/pom.xml | 49 +++++++++++ .../rocketmq/consumer/RocketMqConsumer.java | 81 +++++++++++++++++++ .../consumer/RocketMqConsumerApplication.java | 38 +++++++++ .../RocketMqConsumerController.java | 48 +++++++++++ .../src/main/resources/application.properties | 3 + .../tag-transmission-test/tomcat-demo/pom.xml | 42 ++++++++++ .../tomcatserver/HttpTomcatApplication.java | 38 +++++++++ .../controller/ServerController.java | 58 +++++++++++++ .../src/main/resources/application.properties | 2 + 27 files changed, 1031 insertions(+) create mode 100644 sermant-integration-tests/tag-transmission-test/httpclientv3-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv3/HttpClientApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv3/controller/HttpClientV3Controller.java create mode 100644 sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/httpclientv4-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv4/HttpClientApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv4/controller/HttpClientV4Controller.java create mode 100644 sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/jdkhttp-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jdkhttp/JdkHttpApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jdkhttp/controller/JdkHttpController.java create mode 100644 sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/jetty-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jettyserver/HttpJettyApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jettyserver/controller/ServerController.java create mode 100644 sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/midware-common-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/midware-common-demo/src/main/java/com/huaweicloud/demo/tagtransmission/midware/common/MessageConstant.java create mode 100644 sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumer.java create mode 100644 sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumerApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/controller/RocketMqConsumerController.java create mode 100644 sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/tomcat-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/java/com/huaweicloud/demo/tagtransmission/tomcatserver/HttpTomcatApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/java/com/huaweicloud/demo/tagtransmission/tomcatserver/controller/ServerController.java create mode 100644 sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/resources/application.properties diff --git a/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/pom.xml new file mode 100644 index 0000000000..c4a39e979d --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/pom.xml @@ -0,0 +1,40 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + httpclientv3-demo + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter-web + + + commons-httpclient + commons-httpclient + ${httpclient3x.version} + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv3/HttpClientApplication.java b/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv3/HttpClientApplication.java new file mode 100644 index 0000000000..2a9ea5caa3 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv3/HttpClientApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.httpclientv3; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +public class HttpClientApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(HttpClientApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv3/controller/HttpClientV3Controller.java b/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv3/controller/HttpClientV3Controller.java new file mode 100644 index 0000000000..f0d093cbc5 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv3/controller/HttpClientV3Controller.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.httpclientv3.controller; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; + +/** + * controller,使用httpclient4.x调用http 服务端 + * + * @author daizhenyu + * @since 2023-10-14 + **/ +@RestController +@RequestMapping(value = "httpClientV3") +public class HttpClientV3Controller { + @Value("${common.server.url}") + private String commonServerUrl; + + /** + * 验证httpclient3.x透传流量标签 + * + * @return 流量标签值 + * @throws IOException + */ + @RequestMapping(value = "testHttpClientV3", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testHttpClientV3() throws IOException { + return doHttpClientV3Get(commonServerUrl); + } + + private String doHttpClientV3Get(String url) throws IOException { + // 创建 HttpClient 实例 + HttpClient httpClient = new HttpClient(); + GetMethod getMethod = new GetMethod(url); + + // 执行 GET 请求 + httpClient.executeMethod(getMethod); + String responseContext = getMethod.getResponseBodyAsString(); + getMethod.releaseConnection(); + return responseContext; + } +} diff --git a/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..853e18eb41 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/httpclientv3-demo/src/main/resources/application.properties @@ -0,0 +1,2 @@ +common.server.url=http://127.0.0.1:9040/common/httpServer +server.port=9048 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/pom.xml new file mode 100644 index 0000000000..c8fa8d5606 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/pom.xml @@ -0,0 +1,40 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + httpclientv4-demo + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.apache.httpcomponents + httpclient + ${httpclient4x.version} + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv4/HttpClientApplication.java b/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv4/HttpClientApplication.java new file mode 100644 index 0000000000..f784cd0dc5 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv4/HttpClientApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.httpclientv4; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-09-07 + **/ +@SpringBootApplication +public class HttpClientApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(HttpClientApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv4/controller/HttpClientV4Controller.java b/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv4/controller/HttpClientV4Controller.java new file mode 100644 index 0000000000..e6b47ce31a --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/java/com/huaweicloud/demo/tagtransmission/httpclientv4/controller/HttpClientV4Controller.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.httpclientv4.controller; + +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; + +/** + * controller,使用httpclient3.x调用http 服务端 + * + * @author daizhenyu + * @since 2023-10-14 + **/ +@RestController +@RequestMapping(value = "httpClientV4") +public class HttpClientV4Controller { + @Value("${common.server.url}") + private String commonServerUrl; + + /** + * 验证httpclient4.x透传流量标签 + * + * @return 流量标签值 + * @throws IOException + */ + @RequestMapping(value = "testHttpClientV4", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testHttpClientV4() throws IOException { + return doHttpClientV4Get(commonServerUrl); + } + + private String doHttpClientV4Get(String url) throws IOException { + // 创建 CloseableHttpClient 实例 + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpGet httpGet = new HttpGet(url); + + // 执行 GET 请求 + CloseableHttpResponse response = httpClient.execute(httpGet); + String responseContext = EntityUtils.toString(response.getEntity()); + response.close(); + httpClient.close(); + return responseContext; + } +} diff --git a/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..06a5bf214d --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/httpclientv4-demo/src/main/resources/application.properties @@ -0,0 +1,2 @@ +common.server.url=http://127.0.0.1:9040/common/httpServer +server.port=9049 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/pom.xml new file mode 100644 index 0000000000..fb5f45531a --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/pom.xml @@ -0,0 +1,39 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + jdkhttp-demo + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter-web + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-util-demo + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jdkhttp/JdkHttpApplication.java b/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jdkhttp/JdkHttpApplication.java new file mode 100644 index 0000000000..6c7659ae99 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jdkhttp/JdkHttpApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.jdkhttp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-09-07 + **/ +@SpringBootApplication +public class JdkHttpApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(JdkHttpApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jdkhttp/controller/JdkHttpController.java b/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jdkhttp/controller/JdkHttpController.java new file mode 100644 index 0000000000..21f646d492 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jdkhttp/controller/JdkHttpController.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.jdkhttp.controller; + +import com.huaweicloud.demo.tagtransmission.util.HttpClientUtils; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; + +/** + * controller,使用JdkHttp调用http 服务端 + * + * @author daizhenyu + * @since 2023-10-14 + **/ +@RestController +@RequestMapping(value = "jdkHttp") +public class JdkHttpController { + @Value("${jetty.server.url}") + private String jettyServerUrl; + + @Value("${tomcat.server.url}") + private String tomcatServerUrl; + + /** + * 验证JdkHttp透传流量标签, 调用jetty服务端 + * + * @return 流量标签值 + * @throws IOException + */ + @RequestMapping(value = "testJdkHttpAndJetty", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testJdkHttpAndJetty() { + return HttpClientUtils.doHttpUrlConnectionGet(jettyServerUrl); + } + + /** + * 验证JdkHttp透传流量标签,调用tomcat服务端 + * + * @return 流量标签值 + * @throws IOException + */ + @RequestMapping(value = "testJdkHttpAndTomcat", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testJdkHttpAndTomcat() { + return HttpClientUtils.doHttpUrlConnectionGet(tomcatServerUrl); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..9feca95924 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/jdkhttp-demo/src/main/resources/application.properties @@ -0,0 +1,3 @@ +jetty.server.url=http://127.0.0.1:9051/jetty/testJetty +tomcat.server.url=http://127.0.0.1:9052/tomcat/testTomcat +server.port=9050 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/jetty-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/jetty-demo/pom.xml new file mode 100644 index 0000000000..d736d6c19d --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/jetty-demo/pom.xml @@ -0,0 +1,52 @@ + + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-test + 1.0.0 + + 4.0.0 + + jetty-demo + 1.0.0 + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-jetty + ${spring.boot.version} + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-util-demo + ${tag-transmission.version} + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jettyserver/HttpJettyApplication.java b/sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jettyserver/HttpJettyApplication.java new file mode 100644 index 0000000000..8a73a0937f --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jettyserver/HttpJettyApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.jettyserver; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-09-07 + **/ +@SpringBootApplication +public class HttpJettyApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(HttpJettyApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jettyserver/controller/ServerController.java b/sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jettyserver/controller/ServerController.java new file mode 100644 index 0000000000..9763a08063 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/java/com/huaweicloud/demo/tagtransmission/jettyserver/controller/ServerController.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.jettyserver.controller; + +import com.huaweicloud.demo.tagtransmission.util.HttpClientUtils; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * http Server端,使用jetty作为容器 + * + * @author daizhenyu + * @since 2023-09-07 + **/ +@RestController +@RequestMapping(value = "jetty") +public class ServerController { + @Value("${common.server.url}") + private String commonServerUrl; + + /** + * 验证jetty服务端透传流量标签 + * + * @return 流量标签值 + */ + @RequestMapping(value = "testJetty", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testJetty() { + return HttpClientUtils.doHttpUrlConnectionGet(commonServerUrl); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..75633bd001 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/jetty-demo/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=9051 +common.server.url=http://127.0.0.1:9040/common/httpServer \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/midware-common-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/midware-common-demo/pom.xml new file mode 100644 index 0000000000..8789a9fdcf --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/midware-common-demo/pom.xml @@ -0,0 +1,19 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + midware-common-demo + + + 8 + 8 + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/midware-common-demo/src/main/java/com/huaweicloud/demo/tagtransmission/midware/common/MessageConstant.java b/sermant-integration-tests/tag-transmission-test/midware-common-demo/src/main/java/com/huaweicloud/demo/tagtransmission/midware/common/MessageConstant.java new file mode 100644 index 0000000000..719bba4eb0 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/midware-common-demo/src/main/java/com/huaweicloud/demo/tagtransmission/midware/common/MessageConstant.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.midware.common; + +/** + * 消息中间件的公共常量 + * + * @author daizhenyu + * @since 2023-09-28 + **/ +public class MessageConstant { + /** + * 消息中间件的topic + */ + public static final String TOPIC = "traffic_tag_test"; + + /** + * 时间格式 + */ + public static final String TIME_FORMAT = "yyyy/MM/dd HH:mm:ss"; + + /** + * rocketmq消息的tag + */ + public static final String TAG = ""; + + /** + * rocketmq消费者消费消息的标签范围 + */ + public static final String TAG_SCOPE = "*"; + + /** + * rocketmq生产者组 + */ + public static final String ROCKETMQ_PRODUCE_GROUP = "producer_group"; + + /** + * rocketmq消费者组 + */ + public static final String CONSUME_GROUP = "consume_group"; + + /** + * rocketmq消息体 + */ + public static final String MESSAGE_BODY_ROCKET = "hello inner rocketmq:"; + + /** + * kafka发送消息的key + */ + public static final String KAFKA_KEY = "trafficTag"; + + /** + * kafka消息体 + */ + public static final String MESSAGE_BODY_KAFKA = "hello inner kafka:"; + + /** + * kafka拉去消息的timeout + */ + public static final int KAFKA_CONSUMER_TIMEOUT = 100; + + private MessageConstant() { + } +} diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/pom.xml new file mode 100644 index 0000000000..ebe1b4ad68 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/pom.xml @@ -0,0 +1,49 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + rocketmq-consumer-demo + + + 8 + 8 + + + + + com.huaweicloud.sermant.tagtransmission + midware-common-demo + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-util-demo + + + org.springframework.boot + spring-boot-starter-web + + + org.apache.rocketmq + rocketmq-client + ${rocketmq-client.version} + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumer.java b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumer.java new file mode 100644 index 0000000000..8377f394b1 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumer.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.rocketmq.consumer; + +import com.huaweicloud.demo.tagtransmission.midware.common.MessageConstant; +import com.huaweicloud.demo.tagtransmission.util.HttpClientUtils; + +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext; +import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.common.consumer.ConsumeFromWhere; +import org.apache.rocketmq.common.message.MessageExt; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * kafka消费者 + * + * @author daizhenyu + * @since 2023-09-08 + **/ +@Component +public class RocketMqConsumer implements CommandLineRunner { + /** + * 存储消费者调用http服务端返回的流量标签 + */ + public static final Map ROCKETMQ_TAG_MAP = new HashMap<>(); + + @Value("${common.server.url}") + private String commonServerUrl; + + @Value("${rocketmq.address}") + private String rocketMqAddress; + + @Override + public void run(String[] args) throws MQClientException { + consumeData(); + } + + private void consumeData() throws MQClientException { + DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(MessageConstant.CONSUME_GROUP); + consumer.setNamesrvAddr(rocketMqAddress); + consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET); + consumer.subscribe(MessageConstant.TOPIC, MessageConstant.TAG_SCOPE); + consumer.registerMessageListener(new MessageListenerOrderly() { + @Override + public ConsumeOrderlyStatus consumeMessage(List messageExts, + ConsumeOrderlyContext context) { + if (messageExts != null) { + for (MessageExt ext : messageExts) { + ext.getBody(); + ROCKETMQ_TAG_MAP.put("rocketmqTag", HttpClientUtils.doHttpUrlConnectionGet(commonServerUrl)); + } + } + return ConsumeOrderlyStatus.SUCCESS; + } + }); + consumer.start(); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumerApplication.java b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumerApplication.java new file mode 100644 index 0000000000..b5bf219e6e --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/RocketMqConsumerApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.rocketmq.consumer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +public class RocketMqConsumerApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(RocketMqConsumerApplication.class, args); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/controller/RocketMqConsumerController.java b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/controller/RocketMqConsumerController.java new file mode 100644 index 0000000000..6326e91271 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/rocketmq/consumer/controller/RocketMqConsumerController.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.rocketmq.consumer.controller; + +import com.huaweicloud.demo.tagtransmission.rocketmq.consumer.RocketMqConsumer; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * 消息中间件消费者controller + * + * @author daizhenyu + * @since 2023-09-28 + **/ +@RestController +@RequestMapping(value = "rocketMqConsumer") +public class RocketMqConsumerController { + /** + * 查询rocketmq消费者消费消息后返回的流量标签透传 + * + * @return string + */ + @RequestMapping(value = "queryRocketMqTag", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String queryRocketmqTag() { + String trafficTag = RocketMqConsumer.ROCKETMQ_TAG_MAP.get("rocketmqTag"); + + // 删除流量标签,以免干扰下一次测试查询 + RocketMqConsumer.ROCKETMQ_TAG_MAP.remove("rocketmqTag"); + return trafficTag; + } +} \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..93189e64e9 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/rocketmq-consumer-demo/src/main/resources/application.properties @@ -0,0 +1,3 @@ +common.server.url=http://127.0.0.1:9040/common/httpServer +rocketmq.address=127.0.0.1:9876 +server.port=9056 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/tomcat-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/tomcat-demo/pom.xml new file mode 100644 index 0000000000..6f5c24263e --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/tomcat-demo/pom.xml @@ -0,0 +1,42 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + tomcat-demo + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter-web + ${spring.boot.version} + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-util-demo + ${tag-transmission.version} + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/java/com/huaweicloud/demo/tagtransmission/tomcatserver/HttpTomcatApplication.java b/sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/java/com/huaweicloud/demo/tagtransmission/tomcatserver/HttpTomcatApplication.java new file mode 100644 index 0000000000..7e4abcf56d --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/java/com/huaweicloud/demo/tagtransmission/tomcatserver/HttpTomcatApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.tomcatserver; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +public class HttpTomcatApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(HttpTomcatApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/java/com/huaweicloud/demo/tagtransmission/tomcatserver/controller/ServerController.java b/sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/java/com/huaweicloud/demo/tagtransmission/tomcatserver/controller/ServerController.java new file mode 100644 index 0000000000..4de1b07da0 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/java/com/huaweicloud/demo/tagtransmission/tomcatserver/controller/ServerController.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. + * + * Licensed 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 com.huaweicloud.demo.tagtransmission.tomcatserver.controller; + +import com.huaweicloud.demo.tagtransmission.util.HttpClientUtils; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * http Server端,使用tomcat作为容器 + * + * @author daizhenyu + * @since 2023-09-07 + **/ +@RestController +@RequestMapping(value = "tomcat") +public class ServerController { + @Value("${common.server.url}") + private String commonServerUrl; + + /** + * 验证tomcat服务端透传流量标签 + * + * @return 流量标签值 + */ + @RequestMapping(value = "testTomcat", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testTomcat() { + return HttpClientUtils.doHttpUrlConnectionGet(commonServerUrl); + } + + /** + * 用于验证流量透传标签配置项是否生效 + * + * @return 流量标签值 + */ + @RequestMapping(value = "testConfig", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testConfig() { + return HttpClientUtils.doHttpUrlConnectionGet(commonServerUrl); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..be8bc21db9 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/tomcat-demo/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=9052 +common.server.url=http://127.0.0.1:9040/common/httpServer \ No newline at end of file