From 3b96fc4399a2b24209b73b1c28de83b3099e6dee Mon Sep 17 00:00:00 2001 From: daizhenyu <1449308021@qq.com> Date: Fri, 20 Oct 2023 17:29:46 +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=9Asofarpc=20demo=E3=80=81servicecomb=20demo=E3=80=81?= =?UTF-8?q?okhttp=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sermant-integration-tests/pom.xml | 1 + .../tag-transmission-test/okhttp-demo/pom.xml | 40 ++++ .../okhttp/OkHttpApplication.java | 38 ++++ .../okhttp/controller/OkHttpController.java | 69 +++++++ .../src/main/resources/application.properties | 2 + .../tag-transmission-test/pom.xml | 179 ++++++++++++++++++ .../servicecomb-consumer-demo/pom.xml | 55 ++++++ .../ServiceCombConsumerApplication.java | 40 ++++ .../ServiceCombConsumerController.java | 48 +++++ .../src/main/resources/application.yaml | 28 +++ .../servicecomb-provider-demo/pom.xml | 55 ++++++ .../ServiceCombProviderApplication.java | 40 ++++ .../ServiceCombProviderController.java | 49 +++++ .../src/main/resources/application.properties | 1 + .../src/main/resources/application.yaml | 28 +++ .../sofarpc-consumer-demo/pom.xml | 50 +++++ .../consumer/SofaRpcConsumerApplication.java | 38 ++++ .../controller/SofaRpcConsumerController.java | 64 +++++++ .../src/main/resources/application.properties | 2 + .../sofarpc-provider-demo/pom.xml | 54 ++++++ .../provider/SofaRpcProviderApplication.java | 38 ++++ .../provider/server/SofarpcServer.java | 65 +++++++ .../SofaRpcTagTransmissionServiceImpl.java | 40 ++++ .../src/main/resources/application.properties | 3 + 24 files changed, 1027 insertions(+) create mode 100644 sermant-integration-tests/tag-transmission-test/okhttp-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/okhttp/OkHttpApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/okhttp/controller/OkHttpController.java create mode 100644 sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/consumer/ServiceCombConsumerApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/consumer/controller/ServiceCombConsumerController.java create mode 100644 sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/resources/application.yaml create mode 100644 sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/provider/ServiceCombProviderApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/provider/controller/ServiceCombProviderController.java create mode 100644 sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/resources/application.yaml create mode 100644 sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/consumer/SofaRpcConsumerApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/consumer/controller/SofaRpcConsumerController.java create mode 100644 sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/resources/application.properties create mode 100644 sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/pom.xml create mode 100644 sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/SofaRpcProviderApplication.java create mode 100644 sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/server/SofarpcServer.java create mode 100644 sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/serviceimpl/SofaRpcTagTransmissionServiceImpl.java create mode 100644 sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/resources/application.properties diff --git a/sermant-integration-tests/pom.xml b/sermant-integration-tests/pom.xml index 582af76b41..f89b922409 100644 --- a/sermant-integration-tests/pom.xml +++ b/sermant-integration-tests/pom.xml @@ -32,5 +32,6 @@ agentcore-test dubbo-test spring-test + tag-transmission-test diff --git a/sermant-integration-tests/tag-transmission-test/okhttp-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/okhttp-demo/pom.xml new file mode 100644 index 0000000000..8f3f549a04 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/okhttp-demo/pom.xml @@ -0,0 +1,40 @@ + + + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + + 4.0.0 + + okhttp-demo + + + 8 + 8 + + + + + org.springframework.boot + spring-boot-starter-web + + + com.squareup.okhttp + okhttp + ${okhttpv2.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/okhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/okhttp/OkHttpApplication.java b/sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/okhttp/OkHttpApplication.java new file mode 100644 index 0000000000..b7e508b6f3 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/okhttp/OkHttpApplication.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.okhttp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-09-07 + **/ +@SpringBootApplication +public class OkHttpApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(OkHttpApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/okhttp/controller/OkHttpController.java b/sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/okhttp/controller/OkHttpController.java new file mode 100644 index 0000000000..d2bad2fa47 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/java/com/huaweicloud/demo/tagtransmission/okhttp/controller/OkHttpController.java @@ -0,0 +1,69 @@ +/* + * 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.okhttp.controller; + +import com.squareup.okhttp.OkHttpClient; +import com.squareup.okhttp.Request; +import com.squareup.okhttp.Response; + +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,使用okhttp调用http 服务端 + * + * @author daizhenyu + * @since 2023-10-14 + **/ +@RestController +@RequestMapping(value = "okHttp") +public class OkHttpController { + @Value("${common.server.url}") + private String commonServerUrl; + + /** + * 验证okhttp透传流量标签 + * + * @return 流量标签值 + * @throws IOException + */ + @RequestMapping(value = "testOkHttp", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testOkHttp() throws IOException { + return doOkHttpGet(commonServerUrl); + } + + private String doOkHttpGet(String url) throws IOException { + OkHttpClient client = new OkHttpClient(); + + // 创建 HTTP 请求 + Request request = new Request.Builder() + .url(url) + .build(); + + // 执行请求 + Response response = client.newCall(request).execute(); + String responseContext = response.body().string(); + response.body().close(); + + return responseContext; + } +} diff --git a/sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..ab596f3df0 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/okhttp-demo/src/main/resources/application.properties @@ -0,0 +1,2 @@ +common.server.url=http://127.0.0.1:9040/common/httpServer +server.port=9055 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/pom.xml b/sermant-integration-tests/tag-transmission-test/pom.xml new file mode 100644 index 0000000000..83fa8671b7 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/pom.xml @@ -0,0 +1,179 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 2.7.15 + + + 4.0.0 + + tag-transmission-test + com.huaweicloud.sermant.tagtransmission + 1.0.0 + pom + + + 2.2.0.RELEASE + 1.0.0 + 8 + 8 + 5.0.0 + 2.8.3 + 3.1 + 4.5.13 + 2.7.5 + 2.7.15 + 5.10.0 + 5.1.0 + 2.7.0 + 2.6.12 + 1.52.1 + 3.21.7 + + + + + + com.huaweicloud.sermant.tagtransmission + rpc-api-demo + ${tag-transmission.version} + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-util-demo + ${tag-transmission.version} + + + com.huaweicloud.sermant.tagtransmission + grpc-api-demo + ${tag-transmission.version} + + + com.huaweicloud.sermant.tagtransmission + midware-common-demo + ${tag-transmission.version} + + + + + + httpserver-common-demo + + + + + alibaba-dubbo-test + + alibaba-dubbo-provider-demo + alibaba-dubbo-consumer-demo + rpc-api-demo + tag-transmission-util-demo + + + + apache-dubbo-test + + apache-dubbo-provider-demo + apache-dubbo-consumer-demo + rpc-api-demo + tag-transmission-util-demo + + + + sofarpc-test + + sofarpc-consumer-demo + sofarpc-provider-demo + rpc-api-demo + tag-transmission-util-demo + + + + servicecomb-test + + servicecomb-consumer-demo + servicecomb-provider-demo + rpc-api-demo + tag-transmission-util-demo + + + + grpc-test + + grpc-client-demo + grpc-server-demo + grpc-api-demo + tag-transmission-util-demo + + + + rocketmq-test + + rocketmq-consumer-demo + rocketmq-producer-demo + midware-common-demo + tag-transmission-util-demo + + + + kafka-test + + kafka-consumer-demo + kafka-producer-demo + midware-common-demo + tag-transmission-util-demo + + + + crossthread-test + + crossthread-demo + tag-transmission-util-demo + + + + httpclientv3-test + + httpclientv3-demo + + + + httpclientv4-test + + httpclientv4-demo + + + + okhttp-test + + okhttp-demo + + + + jdkhttp-jetty-test + + jdkhttp-demo + jetty-demo + tag-transmission-util-demo + + + + jdkhttp-tomcat-test + + jdkhttp-demo + tomcat-demo + tag-transmission-util-demo + + + + config-test + + tomcat-demo + tag-transmission-util-demo + + + + \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/pom.xml new file mode 100644 index 0000000000..56db6cb242 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/pom.xml @@ -0,0 +1,55 @@ + + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-test + 1.0.0 + + 4.0.0 + + servicecomb-consumer-demo + + + 8 + 8 + + + + + org.apache.servicecomb + java-chassis-spring-boot-starter-servlet + ${servicecomb.version} + + + org.apache.servicecomb + solution-basic + ${servicecomb.version} + + + org.apache.servicecomb + registry-service-center + ${servicecomb.version} + + + org.apache.servicecomb + servicestage-environment + ${servicecomb.version} + + + com.huaweicloud.sermant.tagtransmission + rpc-api-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/servicecomb-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/consumer/ServiceCombConsumerApplication.java b/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/consumer/ServiceCombConsumerApplication.java new file mode 100644 index 0000000000..e4cfc08f63 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/consumer/ServiceCombConsumerApplication.java @@ -0,0 +1,40 @@ +/* + * 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.servicecomb.consumer; + +import org.apache.servicecomb.springboot2.starter.EnableServiceComb; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +@EnableServiceComb +public class ServiceCombConsumerApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(ServiceCombConsumerApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/consumer/controller/ServiceCombConsumerController.java b/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/consumer/controller/ServiceCombConsumerController.java new file mode 100644 index 0000000000..bf94718e48 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/consumer/controller/ServiceCombConsumerController.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.servicecomb.consumer.controller; + +import com.huaweicloud.demo.tagtransmission.rpc.api.servicecomb.ServiceCombTagTransmissionService; + +import org.apache.servicecomb.provider.pojo.RpcReference; +import org.apache.servicecomb.provider.rest.common.RestSchema; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * servicecomb consumer端controll,用于验证流量标签透传 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@RestSchema(schemaId = "ConsumerController") +@RequestMapping(value = "serviceCombConsumer") +public class ServiceCombConsumerController { + @RpcReference(schemaId = "ProviderController", microserviceName = "servicecomb-provider") + private ServiceCombTagTransmissionService tagTransmissionService; + + /** + * 验证servicecomb rpc透传流量标签 + * + * @return 流量标签值 + */ + @RequestMapping(value = "testServiceCombRpc", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testServiceCombRpc() { + return tagTransmissionService.transmitTag(); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/resources/application.yaml b/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/resources/application.yaml new file mode 100644 index 0000000000..c7c1e69246 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/servicecomb-consumer-demo/src/main/resources/application.yaml @@ -0,0 +1,28 @@ +# override common configurations in common module +servicecomb-config-order: 10 + +servicecomb: + service: + application: servicecomb-test + name: servicecomb-consumer + version: 1.2.0 + registry: + # Default using local service center + address: http://localhost:30100 + # address: https://cse.cn-south-1.myhuaweicloud.com + instance: + watch: false + + nacos: + serverAddr: http://localhost:8848 + group: servicecomb + dataId: servicecomb-1 + namespace: public + contentType: properties + addPrefix: false + + rest: + address: 0.0.0.0:9058 # should be same with server.port to use web container + +server: + port: 9058 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/pom.xml new file mode 100644 index 0000000000..1c9f8c0e5c --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/pom.xml @@ -0,0 +1,55 @@ + + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-test + 1.0.0 + + 4.0.0 + + servicecomb-provider-demo + + + 8 + 8 + + + + + org.apache.servicecomb + java-chassis-spring-boot-starter-servlet + ${servicecomb.version} + + + org.apache.servicecomb + solution-basic + ${servicecomb.version} + + + org.apache.servicecomb + registry-service-center + ${servicecomb.version} + + + org.apache.servicecomb + servicestage-environment + ${servicecomb.version} + + + 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/servicecomb-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/provider/ServiceCombProviderApplication.java b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/provider/ServiceCombProviderApplication.java new file mode 100644 index 0000000000..bf312a8368 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/provider/ServiceCombProviderApplication.java @@ -0,0 +1,40 @@ +/* + * 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.servicecomb.provider; + +import org.apache.servicecomb.springboot2.starter.EnableServiceComb; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +@EnableServiceComb +public class ServiceCombProviderApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(ServiceCombProviderApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/provider/controller/ServiceCombProviderController.java b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/provider/controller/ServiceCombProviderController.java new file mode 100644 index 0000000000..8408a2a5ba --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/servicecomb/provider/controller/ServiceCombProviderController.java @@ -0,0 +1,49 @@ +/* + * 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.servicecomb.provider.controller; + +import com.huaweicloud.demo.tagtransmission.util.HttpClientUtils; + +import org.apache.servicecomb.provider.rest.common.RestSchema; +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; + +/** + * servicecomb provider端controll,用于验证流量标签透传 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@RestSchema(schemaId = "ProviderController") +@RequestMapping(value = "serviceCombProvider") +public class ServiceCombProviderController { + @Value("${common.server.url}") + private String commonServerUrl; + + /** + * 验证servicecomb rpc透传流量标签的服务端方法 + * + * @return 流量标签值 + */ + @RequestMapping(value = "testServiceCombProvider", method = RequestMethod.GET, produces = + MediaType.TEXT_PLAIN_VALUE) + public String transmitTag() { + return HttpClientUtils.doHttpUrlConnectionGet(commonServerUrl); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..bb5741a39b --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/resources/application.properties @@ -0,0 +1 @@ +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/servicecomb-provider-demo/src/main/resources/application.yaml b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/resources/application.yaml new file mode 100644 index 0000000000..36632d0b5d --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/servicecomb-provider-demo/src/main/resources/application.yaml @@ -0,0 +1,28 @@ +# override common configurations in common module +servicecomb-config-order: 10 + +servicecomb: + service: + application: servicecomb-test + name: servicecomb-provider + version: 1.2.0 + registry: + # Default using local service center + address: http://localhost:30100 + # address: https://cse.cn-south-1.myhuaweicloud.com + instance: + watch: false + + nacos: + serverAddr: http://localhost:8848 + group: servicecomb + dataId: servicecomb-1 + namespace: public + contentType: properties + addPrefix: false + + rest: + address: 0.0.0.0:9059 # should be same with server.port to use web container + +server: + port: 9059 diff --git a/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/pom.xml new file mode 100644 index 0000000000..6fe57d41a4 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/pom.xml @@ -0,0 +1,50 @@ + + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-test + 1.0.0 + + 4.0.0 + + sofarpc-consumer-demo + + + 8 + 8 + 1.2 + + + + + org.springframework.boot + spring-boot-starter-web + + + com.huaweicloud.sermant.tagtransmission + rpc-api-demo + + + com.alipay.sofa + sofa-rpc-all + ${sofarpc.version} + + + commons-logging + commons-logging + ${common.log.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/sofarpc-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/consumer/SofaRpcConsumerApplication.java b/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/consumer/SofaRpcConsumerApplication.java new file mode 100644 index 0000000000..8c93941e5b --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/consumer/SofaRpcConsumerApplication.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.sofarpc.consumer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +public class SofaRpcConsumerApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(SofaRpcConsumerApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/consumer/controller/SofaRpcConsumerController.java b/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/consumer/controller/SofaRpcConsumerController.java new file mode 100644 index 0000000000..beb632984b --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/consumer/controller/SofaRpcConsumerController.java @@ -0,0 +1,64 @@ +/* + * 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.sofarpc.consumer.controller; + +import com.huaweicloud.demo.tagtransmission.rpc.api.sofarpc.SofaRpcTagTransmissionService; + +import com.alipay.sofa.rpc.config.ConsumerConfig; + +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; + +/** + * 用于验证sofarpc 透传流量标签 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@RestController +@RequestMapping(value = "sofaRpc") +public class SofaRpcConsumerController { + private static final int SOFARPC_TIMEOUT = 10000; + + @Value("${sofa.rpc.url}") + private String sofaRpcUrl; + + private ConsumerConfig sofaConsumerConfig; + + /** + * 验证sofarpc透传流量标签 + * + * @return 流量标签值 + */ + @RequestMapping(value = "testSofaRpc", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + public String testSofaRpc() { + if (sofaConsumerConfig == null) { + synchronized (this) { + if (sofaConsumerConfig == null) { + sofaConsumerConfig = new ConsumerConfig() + .setInterfaceId(SofaRpcTagTransmissionService.class.getName()) + .setDirectUrl(sofaRpcUrl) + .setConnectTimeout(SOFARPC_TIMEOUT); + } + } + } + return sofaConsumerConfig.refer().transmitTag(); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..eb60dd1dcf --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/sofarpc-consumer-demo/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=9060 +sofa.rpc.url=bolt://127.0.0.1:12001 \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/pom.xml b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/pom.xml new file mode 100644 index 0000000000..86ee815d87 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/pom.xml @@ -0,0 +1,54 @@ + + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-test + 1.0.0 + + 4.0.0 + + sofarpc-provider-demo + + + 8 + 8 + 1.2 + + + + + org.springframework.boot + spring-boot-starter-web + + + com.huaweicloud.sermant.tagtransmission + rpc-api-demo + + + com.huaweicloud.sermant.tagtransmission + tag-transmission-util-demo + + + com.alipay.sofa + sofa-rpc-all + ${sofarpc.version} + + + commons-logging + commons-logging + ${common.log.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/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/SofaRpcProviderApplication.java b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/SofaRpcProviderApplication.java new file mode 100644 index 0000000000..ca135cfb51 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/SofaRpcProviderApplication.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.sofarpc.provider; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * springboot 启动类 + * + * @author daizhenyu + * @since 2023-10-13 + **/ +@SpringBootApplication +public class SofaRpcProviderApplication { + /** + * 启动类 + * + * @param args 进程启动入参 + */ + public static void main(String[] args) { + SpringApplication.run(SofaRpcProviderApplication.class, args); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/server/SofarpcServer.java b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/server/SofarpcServer.java new file mode 100644 index 0000000000..05b0d12a7b --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/server/SofarpcServer.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.sofarpc.provider.server; + +import com.huaweicloud.demo.tagtransmission.rpc.api.sofarpc.SofaRpcTagTransmissionService; +import com.huaweicloud.demo.tagtransmission.sofarpc.provider.serviceimpl.SofaRpcTagTransmissionServiceImpl; + +import com.alipay.sofa.rpc.config.ProviderConfig; +import com.alipay.sofa.rpc.config.ServerConfig; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +/** + * sofarpc 服务端启动 + * + * @author daizhenyu + * @since 2023-09-28 + **/ +@Component +public class SofarpcServer implements CommandLineRunner { + @Value("${sofarpc.server.port}") + private int sofaRpcPort; + + @Autowired + private SofaRpcTagTransmissionServiceImpl sofaRpcTagTransmissionService; + + @Override + public void run(String[] args) { + ServerConfig serverConfig = new ServerConfig() + // 设置一个协议,默认bolt + .setProtocol("bolt") + // 设置一个端口 + .setPort(sofaRpcPort) + // 非守护线程 + .setDaemon(false); + + ProviderConfig providerConfig = + new ProviderConfig() + // 指定接口 + .setInterfaceId(SofaRpcTagTransmissionService.class.getName()) + // 指定实现 + .setRef(sofaRpcTagTransmissionService) + // 指定服务端 + .setServer(serverConfig); + + providerConfig.export(); + } +} diff --git a/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/serviceimpl/SofaRpcTagTransmissionServiceImpl.java b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/serviceimpl/SofaRpcTagTransmissionServiceImpl.java new file mode 100644 index 0000000000..bc00fc08ef --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/java/com/huaweicloud/demo/tagtransmission/sofarpc/provider/serviceimpl/SofaRpcTagTransmissionServiceImpl.java @@ -0,0 +1,40 @@ +/* + * 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.sofarpc.provider.serviceimpl; + +import com.huaweicloud.demo.tagtransmission.rpc.api.sofarpc.SofaRpcTagTransmissionService; +import com.huaweicloud.demo.tagtransmission.util.HttpClientUtils; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * sofarpc服务实现类 + * + * @author daizhenyu + * @since 2023-09-08 + **/ +@Component +public class SofaRpcTagTransmissionServiceImpl implements SofaRpcTagTransmissionService { + @Value("${common.server.url}") + private String commomServerUrl; + + @Override + public String transmitTag() { + return HttpClientUtils.doHttpUrlConnectionGet(commomServerUrl); + } +} \ No newline at end of file diff --git a/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/resources/application.properties b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/resources/application.properties new file mode 100644 index 0000000000..f4b87cbb97 --- /dev/null +++ b/sermant-integration-tests/tag-transmission-test/sofarpc-provider-demo/src/main/resources/application.properties @@ -0,0 +1,3 @@ +server.port=9061 +sofarpc.server.port=12001 +common.server.url=http://127.0.0.1:9040/common/httpServer \ No newline at end of file