diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 38cd68c..3263402 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -28,5 +28,4 @@ jobs: ${{ runner.os }}-maven - name: Compilation and Installation run: bash scripts/build.sh install - - name: publish coverage report - run: bash <(curl -s https://codecov.io/bash) + diff --git a/README.md b/README.md index 17220e7..159c372 100644 --- a/README.md +++ b/README.md @@ -100,27 +100,62 @@ dubbo.servicecomb.governance: {"providerInfos":[{"serviceName":"price-provider", * POM 中引入依赖 - ```yaml - - com.huaweicloud.dubbo-servicecomb - dubbo-servicecomb-service-center - - - com.huaweicloud.dubbo-servicecomb - dubbo-servicecomb-config-center - ``` + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-service-center + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-config-center + + ``` + 上面两个部件,实现 dubbo 应用的注册和动态配置、服务治理配置项检测等功能。 -* 采用 Spring 启动(目前只支持 Spring 启动方式)。 +* 采用 Spring 启动 Spring 扫描路径中,需要增加 `classpath*:spring/dubbo-servicecomb.xml`, 举例如下: - ```java - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "classpath*:spring/dubbo-provider.xml", "classpath*:spring/dubbo-servicecomb.xml"); ``` + public class PriceApplication { + public static void main(String[] args) throws Exception { + try { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "classpath*:spring/dubbo-provider.xml", "classpath*:spring/dubbo-servicecomb.xml"); + context.start(); + System.in.read(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + ``` + + * 采用 Spring Boot 启动 + Spring 扫描路径中,需要增加 `classpath*:spring/dubbo-servicecomb.xml`, 举例如下: + + ``` + @SpringBootApplication + @ImportResource({"classpath*:spring/dubbo-provider.xml", "classpath*:spring/dubbo-servicecomb.xml"}) + public class PriceApplication { + public static void main(String[] args) throws Exception { + try { + SpringApplication.run(PriceApplication.class); + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + ``` - 如果使用 Spring Boot, 也可以采用 @ImportResource 等标签引入 dubbo-servicecomb 相关 bean。 + Spring Boot 启动,需要额外依赖如下 jar 包: + + ``` + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-spring-boot + + ``` * 使用 service center 作为注册发现。 在 Spring 配置文件中增加如下配置。 如果配置文件已经配置了 zookeeper, 那么需要使用下面的配置项进行替换。 diff --git a/dependencies/pom.xml b/dependencies/pom.xml index a713504..fd1ef71 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -34,6 +34,26 @@ + + jakarta.servlet + jakarta.servlet-api + 4.0.3 + + + jakarta.validation + jakarta.validation-api + 2.0.2 + + + org.hibernate.validator + hibernate-validator + 6.1.5.Final + + + org.yaml + snakeyaml + 1.24 + com.fasterxml.jackson jackson-bom @@ -41,6 +61,13 @@ import pom + + org.springframework + spring-framework-bom + ${spring.version} + pom + import + com.alibaba dubbo-bom @@ -55,6 +82,13 @@ pom import + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + junit junit diff --git a/integration-tests/discovery-tests-spring-boot/README.md b/integration-tests/discovery-tests-spring-boot/README.md new file mode 100644 index 0000000..82334dc --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/README.md @@ -0,0 +1,13 @@ +运行测试的步骤: + +1. 安装本地微服务引擎并启动 +2. 运行 PriceApplication +3. 运行 OrderApplication +4. 配置中心下发配置项: + + [全局配置] dubbo.servicecomb.test.configuration: peizhi + [服务配置:price-provider] dubbo.servicecomb.test.configurationService: peizhi_service + [全局配置] dubbo.servicecomb.governance: {"providerInfos":[{"serviceName":"price-provider","schemaInfos":[{"schemaId":"com.huaweicloud.it.price.PriceService","parameters":{"timeout":5000}}]}]} + +5. 运行 PortalApplication 查看测试结果, 如果成功,输出 `running all test cases successfully` + diff --git a/integration-tests/discovery-tests-spring-boot/common-api/pom.xml b/integration-tests/discovery-tests-spring-boot/common-api/pom.xml new file mode 100644 index 0000000..604f6ad --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/common-api/pom.xml @@ -0,0 +1,35 @@ + + + + + com.huaweicloud.dubbo-servicecomb + spring-boot-discovery-tests + 1.1.3-SNAPSHOT + + + 4.0.0 + + spring-boot-discovery-common-api + + + + + + \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/common-api/src/main/java/com/huaweicloud/it/price/PingService.java b/integration-tests/discovery-tests-spring-boot/common-api/src/main/java/com/huaweicloud/it/price/PingService.java new file mode 100644 index 0000000..0dc8acd --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/common-api/src/main/java/com/huaweicloud/it/price/PingService.java @@ -0,0 +1,22 @@ +/* + * 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 com.huaweicloud.it.price; + +public interface PingService { + boolean ping(); +} diff --git a/integration-tests/discovery-tests-spring-boot/common-api/src/main/java/com/huaweicloud/it/price/PriceService.java b/integration-tests/discovery-tests-spring-boot/common-api/src/main/java/com/huaweicloud/it/price/PriceService.java new file mode 100644 index 0000000..306734f --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/common-api/src/main/java/com/huaweicloud/it/price/PriceService.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 com.huaweicloud.it.price; + +import java.util.concurrent.CompletableFuture; + +public interface PriceService { + String sayHello(String name); + + CompletableFuture sayHelloAsync(String name); + + String testConfiguration(String value); + + String testConfigurationService(String value); +} diff --git a/integration-tests/discovery-tests-spring-boot/common-api/src/main/java/com/huaweicloud/it/price/PriceServiceRest.java b/integration-tests/discovery-tests-spring-boot/common-api/src/main/java/com/huaweicloud/it/price/PriceServiceRest.java new file mode 100644 index 0000000..a85d190 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/common-api/src/main/java/com/huaweicloud/it/price/PriceServiceRest.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 com.huaweicloud.it.price; + +import java.util.concurrent.CompletableFuture; + +public interface PriceServiceRest { + String sayHello(String name); + + CompletableFuture sayHelloAsync(String name); + + String testConfiguration(String value); + + String testConfigurationService(String value); +} diff --git a/integration-tests/discovery-tests-spring-boot/discovery-tests-client/pom.xml b/integration-tests/discovery-tests-spring-boot/discovery-tests-client/pom.xml new file mode 100644 index 0000000..a7c3f9c --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/discovery-tests-client/pom.xml @@ -0,0 +1,244 @@ + + + + + com.huaweicloud.dubbo-servicecomb + spring-boot-discovery-tests + 1.1.3-SNAPSHOT + + + + 2.1.6.RELEASE + 5.1.14.RELEASE + + 1.3.2 + + + + 4.0.0 + + spring-boot-discovery-tests-client + + + + com.huaweicloud + spring-cloud-huawei-dependencies + ${spring-cloud-huawei.version} + pom + import + + + org.springframework + spring-framework-bom + ${spring.version} + pom + import + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-dependencies + ${project.version} + import + pom + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + jakarta.servlet + jakarta.servlet-api + 4.0.3 + + + jakarta.validation + jakarta.validation-api + 2.0.2 + + + org.hibernate.validator + hibernate-validator + 6.1.5.Final + + + org.yaml + snakeyaml + 1.24 + + + junit + junit + 4.12 + + + + + + + com.huaweicloud.dubbo-servicecomb + discovery-common-api + ${project.version} + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + com.huaweicloud + spring-cloud-starter-huawei-servicecomb-discovery + + + + + + docker + + + + io.fabric8 + docker-maven-plugin + + + + + servicecomb/service-center + service-center + + + server is ready + + + 30100 + + + + + + service.center.port:30100 + + + + + + + price-provider-test:${project.version} + price-provider-test + + + + -Dspring.cloud.servicecomb.discovery.address=http://sc.servicecomb.io:30100 + + /maven/price-provider-test-${project.version}.jar + + + service-center:sc.servicecomb.io + + + watching microservice successfully + + + 8080 + + + + + + 8080:8080 + + + service-center + + + + + + order-consumer-test:${project.version} + order-consumer-test + + + + -Dspring.cloud.servicecomb.discovery.address=http://sc.servicecomb.io:30100 + + /maven/order-consumer-test-${project.version}.jar + + + service-center:sc.servicecomb.io + + + watching microservice successfully + + + 8088 + + + + + + 8088:8088 + + + service-center + + + + + + + + start + pre-integration-test + + start + + + + stop + post-integration-test + + stop + + + + + + com.github.odavid.maven.plugins + mixin-maven-plugin + + + + com.huaweicloud.dubbo-servicecomb + docker-run-config + ${project.version} + + + + + + + + + \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/discovery-tests-client/src/main/java/com/huaweicloud/it/portal/PortalApplication.java b/integration-tests/discovery-tests-spring-boot/discovery-tests-client/src/main/java/com/huaweicloud/it/portal/PortalApplication.java new file mode 100644 index 0000000..b978e39 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/discovery-tests-client/src/main/java/com/huaweicloud/it/portal/PortalApplication.java @@ -0,0 +1,59 @@ +/* + * 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 com.huaweicloud.it.portal; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +@SpringBootApplication +@Component +public class PortalApplication { + private static PortalController portalController; + + @LoadBalanced + @Bean + public RestTemplate restTemplate() { + RestTemplate restTemplate = new RestTemplate(); + return restTemplate; + } + + @Autowired + void setPortalController(PortalController portalController) { + PortalApplication.portalController = portalController; + } + + + public static void main(String[] args) throws Exception { + try { + SpringApplication.run(PortalApplication.class); + } catch (Throwable e) { + e.printStackTrace(); + } + + Thread.sleep(3000); // TODO: 尽可能规避 spring cloud huawei 的 bug, 需要等待新版本 + + System.out.println("running all test cases"); + portalController.testAll(); + System.out.println("running all test cases successfully"); + } +} diff --git a/integration-tests/discovery-tests-spring-boot/discovery-tests-client/src/main/java/com/huaweicloud/it/portal/PortalController.java b/integration-tests/discovery-tests-spring-boot/discovery-tests-client/src/main/java/com/huaweicloud/it/portal/PortalController.java new file mode 100644 index 0000000..73ea6ed --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/discovery-tests-client/src/main/java/com/huaweicloud/it/portal/PortalController.java @@ -0,0 +1,48 @@ +/* + * 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 com.huaweicloud.it.portal; + +import org.junit.Assert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +@RestController +@RequestMapping(path = "/portal") +public class PortalController { + @Autowired + private RestTemplate restTemplate; + + @GetMapping(path = "testAll") + public void testAll() { + + String result = restTemplate.getForObject("http://order-consumer/price/sayHello?name={name}", String.class, "hello world"); + Assert.assertEquals(result, "hello world"); + + result = restTemplate.getForObject("http://order-consumer/price/sayHello?name={name}", String.class, "timeout"); + Assert.assertEquals(result, "timeout"); + + result = restTemplate.getForObject("http://order-consumer/price/testConfiguration", String.class); + Assert.assertEquals(result, "peizhi"); + + result = restTemplate.getForObject("http://order-consumer/price/testConfigurationService", String.class); + Assert.assertEquals(result, "peizhi_service"); + } +} diff --git a/integration-tests/discovery-tests-spring-boot/discovery-tests-client/src/main/resources/application.yml b/integration-tests/discovery-tests-spring-boot/discovery-tests-client/src/main/resources/application.yml new file mode 100644 index 0000000..6633a4b --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/discovery-tests-client/src/main/resources/application.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. +## --------------------------------------------------------------------------- + +server: + port: 8088 + +spring: + application: + name: portal-consumer + cloud: + servicecomb: + discovery: + enabled: true + address: http://127.0.0.1:30100 + appName: discovery + serviceName: portal-consumer + version: 0.0.1 \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/order-consumer/pom.xml b/integration-tests/discovery-tests-spring-boot/order-consumer/pom.xml new file mode 100644 index 0000000..f0c35ad --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/order-consumer/pom.xml @@ -0,0 +1,137 @@ + + + + + com.huaweicloud.dubbo-servicecomb + spring-boot-discovery-tests + 1.1.3-SNAPSHOT + + + 4.0.0 + + spring-boot-order-consumer-test + + + + org.springframework.boot + spring-boot-starter-web + + + jakarta.servlet + jakarta.servlet-api + + + jakarta.validation + jakarta.validation-api + + + com.huaweicloud.dubbo-servicecomb + discovery-common-api + ${project.version} + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-service-center + ${project.version} + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-config-center + ${project.version} + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-spring-boot + ${project.version} + + + com.alibaba + dubbo-config-spring + + + com.alibaba + dubbo-registry-zookeeper + + + com.alibaba + dubbo-registry-multicast + + + com.alibaba + dubbo-rpc-dubbo + + + com.alibaba + dubbo-rpc-rest + + + com.alibaba + dubbo-remoting-netty4 + + + com.alibaba + dubbo-serialization-hessian2 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + docker + + 8088 + + + + + io.fabric8 + docker-maven-plugin + + + org.commonjava.maven.plugins + directory-maven-plugin + + + com.github.odavid.maven.plugins + mixin-maven-plugin + + + + com.huaweicloud.dubbo-servicecomb + docker-build-config + ${project.version} + + + + + + + + + \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/java/com/huaweicloud/it/order/OrderApplication.java b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/java/com/huaweicloud/it/order/OrderApplication.java new file mode 100644 index 0000000..695d0c4 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/java/com/huaweicloud/it/order/OrderApplication.java @@ -0,0 +1,62 @@ +/* + * 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 com.huaweicloud.it.order; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.ImportResource; +import org.springframework.stereotype.Component; + +import com.huaweicloud.it.price.PingService; +import com.huaweicloud.it.price.PriceService; + +@SpringBootApplication +@ImportResource({"classpath*:spring/dubbo-provider.xml", "classpath*:spring/dubbo-servicecomb.xml"}) +@Component +public class OrderApplication { + private static ApplicationContext context; + + @Autowired + public void setApplicationContext(ApplicationContext context) { + OrderApplication.context = context; + } + + public static void main(String[] args) throws Exception { + try { + SpringApplication.run(OrderApplication.class); + } catch (Throwable e) { + e.printStackTrace(); + } + + PriceService priceService = context.getBean("priceService", PriceService.class); + PingService pingService = context.getBean("pingService", PingService.class); + + while (true) { + try { + Thread.sleep(3000); + System.out.println(priceService.sayHello("===========================hello")); + System.out.println(pingService.ping()); + System.out.println(priceService.sayHello("timeout")); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } + } +} \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/java/com/huaweicloud/it/order/PriceServiceRestImpl.java b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/java/com/huaweicloud/it/order/PriceServiceRestImpl.java new file mode 100644 index 0000000..67c9961 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/java/com/huaweicloud/it/order/PriceServiceRestImpl.java @@ -0,0 +1,72 @@ +/* + * 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 com.huaweicloud.it.order; + +import java.util.concurrent.CompletableFuture; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +import com.huaweicloud.it.price.PriceService; +import com.huaweicloud.it.price.PriceServiceRest; + +@Path("/price") +public class PriceServiceRestImpl implements PriceServiceRest { + @Autowired + @Qualifier("priceService") + private PriceService priceService; + + @Override + @GET + @Path("/sayHello") + @Produces({MediaType.APPLICATION_JSON}) + public String sayHello(@QueryParam("name") String name) { + return priceService.sayHello(name); + } + + // dubbo do not support CompletableFuture, this example can not work + @Override + @GET + @Path("/sayHelloAsync") + @Produces({MediaType.APPLICATION_JSON}) + public CompletableFuture sayHelloAsync(@QueryParam("name") String name) { + return CompletableFuture.completedFuture(name); + } + + @Override + @GET + @Path("/testConfiguration") + @Produces({MediaType.APPLICATION_JSON}) + public String testConfiguration(String value) { + return priceService.testConfiguration(value); + } + + @Override + @GET + @Path("/testConfigurationService") + @Produces({MediaType.APPLICATION_JSON}) + public String testConfigurationService(String value) { + return priceService.testConfigurationService(value); + } +} diff --git a/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/application.yml b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/application.yml new file mode 100644 index 0000000..46dcd20 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/application.yml @@ -0,0 +1,19 @@ +## --------------------------------------------------------------------------- +## 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: 8085 \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/dubbo.properties b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/dubbo.properties new file mode 100644 index 0000000..404c63e --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/dubbo.properties @@ -0,0 +1,29 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +dubbo.application.qos.port=33333 + +dubbo.servicecomb.service.application=discovery +dubbo.servicecomb.service.name=order-consumer +dubbo.servicecomb.service.version=1.0.0 + + +#### Ϣ #### +dubbo.servicecomb.registry.address=http://127.0.0.1:30100 + +#### Ϣ #### +dubbo.servicecomb.config.address=http://127.0.0.1:30113 \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/log4j.properties b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/log4j.properties new file mode 100644 index 0000000..b31342a --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/log4j.properties @@ -0,0 +1,24 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +###set log levels### +log4j.rootLogger=info, stdout +###output to the console### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/spring/dubbo-provider.xml b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/spring/dubbo-provider.xml new file mode 100644 index 0000000..1e0bdaa --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/order-consumer/src/main/resources/spring/dubbo-provider.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + diff --git a/integration-tests/discovery-tests-spring-boot/pom.xml b/integration-tests/discovery-tests-spring-boot/pom.xml new file mode 100644 index 0000000..30c7e2b --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/pom.xml @@ -0,0 +1,48 @@ + + + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-integration-tests + 1.1.3-SNAPSHOT + + + 4.0.0 + spring-boot-discovery-tests + pom + + + + + + org.apache.httpcomponents + httpclient + 4.5.7 + + + + + common-api + price-provider + order-consumer + discovery-tests-client + + + \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/price-provider/pom.xml b/integration-tests/discovery-tests-spring-boot/price-provider/pom.xml new file mode 100644 index 0000000..2d4e498 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/price-provider/pom.xml @@ -0,0 +1,132 @@ + + + + + com.huaweicloud.dubbo-servicecomb + spring-boot-discovery-tests + 1.1.3-SNAPSHOT + + + 4.0.0 + + spring-boot-price-provider-test + + + + org.springframework.boot + spring-boot-starter-web + + + jakarta.servlet + jakarta.servlet-api + + + jakarta.validation + jakarta.validation-api + + + com.huaweicloud.dubbo-servicecomb + discovery-common-api + ${project.version} + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-service-center + ${project.version} + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-config-center + ${project.version} + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-spring-boot + ${project.version} + + + com.alibaba + dubbo-config-spring + + + com.alibaba + dubbo-registry-zookeeper + + + com.alibaba + dubbo-registry-multicast + + + com.alibaba + dubbo-rpc-dubbo + + + com.alibaba + dubbo-remoting-netty4 + + + com.alibaba + dubbo-serialization-hessian2 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + docker + + 8080 + + + + + io.fabric8 + docker-maven-plugin + + + org.commonjava.maven.plugins + directory-maven-plugin + + + com.github.odavid.maven.plugins + mixin-maven-plugin + + + + com.huaweicloud.dubbo-servicecomb + docker-build-config + ${project.version} + + + + + + + + + \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/price-provider/src/main/java/com/huaweicloud/it/price/PingServiceImpl.java b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/java/com/huaweicloud/it/price/PingServiceImpl.java new file mode 100644 index 0000000..147f5f7 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/java/com/huaweicloud/it/price/PingServiceImpl.java @@ -0,0 +1,25 @@ +/* + * 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 com.huaweicloud.it.price; + +public class PingServiceImpl implements PingService { + @Override + public boolean ping() { + return true; + } +} diff --git a/integration-tests/discovery-tests-spring-boot/price-provider/src/main/java/com/huaweicloud/it/price/PriceApplication.java b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/java/com/huaweicloud/it/price/PriceApplication.java new file mode 100644 index 0000000..6bd15d8 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/java/com/huaweicloud/it/price/PriceApplication.java @@ -0,0 +1,34 @@ +/* + * 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 com.huaweicloud.it.price; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportResource; + +@SpringBootApplication +@ImportResource({"classpath*:spring/dubbo-provider.xml", "classpath*:spring/dubbo-servicecomb.xml"}) +public class PriceApplication { + public static void main(String[] args) throws Exception { + try { + SpringApplication.run(PriceApplication.class); + } catch (Throwable e) { + e.printStackTrace(); + } + } +} diff --git a/integration-tests/discovery-tests-spring-boot/price-provider/src/main/java/com/huaweicloud/it/price/PriceServiceImpl.java b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/java/com/huaweicloud/it/price/PriceServiceImpl.java new file mode 100644 index 0000000..43996ad --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/java/com/huaweicloud/it/price/PriceServiceImpl.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.huaweicloud.it.price; + +import java.util.concurrent.CompletableFuture; + +import org.springframework.beans.factory.annotation.Value; + +public class PriceServiceImpl implements PriceService { + @Value("${dubbo.servicecomb.test.configuration:hello}") + private String configuration; + + @Value("${dubbo.servicecomb.test.configurationService:hello}") + private String configurationService; + + @Override + public String sayHello(String name) { + if ("timeout".equals(name)) { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + return name; + } + + @Override + public CompletableFuture sayHelloAsync(String name) { + return CompletableFuture.completedFuture(sayHello(name)); + } + + @Override + public String testConfiguration(String value) { + return configuration; + } + + @Override + public String testConfigurationService(String value) { + return configurationService; + } +} diff --git a/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/application.yml b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/application.yml new file mode 100644 index 0000000..af6fe4c --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/application.yml @@ -0,0 +1,19 @@ +## --------------------------------------------------------------------------- +## 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: 8084 \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/dubbo.properties b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/dubbo.properties new file mode 100644 index 0000000..b51e3a0 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/dubbo.properties @@ -0,0 +1,67 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +dubbo.application.qos.port=22222 + +#### Ϣ #### +# Ӧá +dubbo.servicecomb.service.application=discovery +# ơ +dubbo.servicecomb.service.name=price-provider +# 汾ĬΪ 1.0.0.0 +dubbo.servicecomb.service.version=1.0.0 +# ĬΪաѡֵdevelopment, testing, acceptance, production +# dubbo.servicecomb.service.environment=production +# project ĬΪ default +# dubbo.servicecomb.service.project= +#### END + +#### ʵϢ #### +# ʵʼ״̬ѡֵ UP, DOWN, STARTING, OUTOFSERVICE +# dubbo.servicecomb.instance.initialStatus=UP +#### END + +#### Ϣ #### +dubbo.servicecomb.registry.address=http://127.0.0.1:30100 + +#### Ϣ #### +dubbo.servicecomb.config.address=http://127.0.0.1:30113 + +#### SSL Ϣ #### +#dubbo.servicecomb.ssl.enabled=true +# ssl engine. ĬΪ JDK ѡ OPENSSL +#dubbo.servicecomb.ssl.engine= +# ssl protocols Ĭ TLSv1.2 +#dubbo.servicecomb.ssl.protocols= +# ssl ciphersĬ TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 +#dubbo.servicecomb.ssl.ciphers= +#dubbo.servicecomb.ssl.authPeer=false +#dubbo.servicecomb.ssl.trustStore= +#dubbo.servicecomb.ssl.trustStoreType= +#dubbo.servicecomb.ssl.trustStoreValue= +#dubbo.servicecomb.ssl.keyStore= +#dubbo.servicecomb.ssl.keyStoreType= +#dubbo.servicecomb.ssl.keyStoreValue= +#dubbo.servicecomb.ssl.crl= +#dubbo.servicecomb.ssl.sslCustomClass= + +#### AK/SK ֤ #### +#dubbo.servicecomb.credentials.enabled=true +#dubbo.servicecomb.credentials.accessKey= +#dubbo.servicecomb.credentials.secretKey= +#dubbo.servicecomb.credentials.cipher= +#dubbo.servicecomb.credentials.project=cn-south-1 diff --git a/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/log4j.properties b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/log4j.properties new file mode 100644 index 0000000..b31342a --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/log4j.properties @@ -0,0 +1,24 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +###set log levels### +log4j.rootLogger=info, stdout +###output to the console### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n \ No newline at end of file diff --git a/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/spring/dubbo-provider.xml b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/spring/dubbo-provider.xml new file mode 100644 index 0000000..330d0a6 --- /dev/null +++ b/integration-tests/discovery-tests-spring-boot/price-provider/src/main/resources/spring/dubbo-provider.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 129a96e..e52640e 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -34,6 +34,7 @@ docker-build-config docker-run-config discovery-tests + discovery-tests-spring-boot diff --git a/pom.xml b/pom.xml index b7d0011..92161c8 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,8 @@ 2.6.9 2.1.1 2.10.0 + 2.1.6.RELEASE + 5.1.14.RELEASE UTF-8 -Dfile.encoding=UTF-8 @@ -48,6 +50,8 @@ common discovery config + + spring-boot diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml new file mode 100644 index 0000000..37d2560 --- /dev/null +++ b/spring-boot/pom.xml @@ -0,0 +1,38 @@ + + + + + com.huaweicloud.dubbo-servicecomb + dubbo-servicecomb-parents + 1.1.3-SNAPSHOT + ../parents + + + + 4.0.0 + dubbo-servicecomb-spring-boot + + + + org.springframework.boot + spring-boot + + + \ No newline at end of file diff --git a/spring-boot/src/main/java/com/huaweicloud/dubbo/springboot/SpringBootApplicationEventListener.java b/spring-boot/src/main/java/com/huaweicloud/dubbo/springboot/SpringBootApplicationEventListener.java new file mode 100644 index 0000000..788c1fa --- /dev/null +++ b/spring-boot/src/main/java/com/huaweicloud/dubbo/springboot/SpringBootApplicationEventListener.java @@ -0,0 +1,44 @@ +/* + * 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 com.huaweicloud.dubbo.springboot; + +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.ApplicationEventPublisherAware; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextStartedEvent; + +public class SpringBootApplicationEventListener implements ApplicationListener, + ApplicationEventPublisherAware { + + private ApplicationEventPublisher applicationEventPublisher; + + @Override + public void onApplicationEvent(ApplicationEvent event) { + if (event instanceof ApplicationStartedEvent) { + this.applicationEventPublisher + .publishEvent(new ContextStartedEvent(((ApplicationStartedEvent) event).getApplicationContext())); + } + } + + @Override + public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { + this.applicationEventPublisher = applicationEventPublisher; + } +} diff --git a/spring-boot/src/main/resources/spring/dubbo-servicecomb.xml b/spring-boot/src/main/resources/spring/dubbo-servicecomb.xml new file mode 100644 index 0000000..74c316f --- /dev/null +++ b/spring-boot/src/main/resources/spring/dubbo-servicecomb.xml @@ -0,0 +1,25 @@ + + + + + + +