This is an automated email from the ASF dual-hosted git repository. songxiaosheng pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/dubbo-spi-samples.git
The following commit(s) were added to refs/heads/main by this push: new a88d34c feat:add metadata-samples (#12) a88d34c is described below commit a88d34c540fbd2efd2368e717cf3ece6441fab89 Author: 其一 <78294896+qy...@users.noreply.github.com> AuthorDate: Wed Jul 10 18:01:55 2024 +0800 feat:add metadata-samples (#12) * feat:add metadata-samples * feat:add Licensed * feat:add tests * feat: code format --------- Co-authored-by: 其一 <yuanhon...@cai-inc.com> --- .../samples-spi-metadata/pom.xml | 28 ++++++ .../samples-spi-metadata-consul/pom.xml | 110 +++++++++++++++++++++ .../dubbo/samples/spi/metadata/ConsulConsumer.java | 38 +++++++ .../dubbo/samples/spi/metadata/ConsulProvider.java | 37 +++++++ .../samples/spi/metadata/api/DemoService.java | 26 +++++ .../samples/spi/metadata/impl/DemoServiceImpl.java | 35 +++++++ .../src/main/resources/log4j2.xml | 29 ++++++ .../src/main/resources/spring/consul-consumer.xml | 35 +++++++ .../src/main/resources/spring/consul-provider.xml | 38 +++++++ .../src/test/java/metadata/DemoServiceIT.java | 42 ++++++++ .../samples-spi-metadata-etcd/pom.xml | 110 +++++++++++++++++++++ .../dubbo/samples/spi/metadata/EtcdConsumer.java | 36 +++++++ .../dubbo/samples/spi/metadata/EtcdProvider.java | 37 +++++++ .../samples/spi/metadata/api/DemoService.java | 26 +++++ .../samples/spi/metadata/impl/DemoServiceImpl.java | 35 +++++++ .../src/main/resources/log4j2.xml | 29 ++++++ .../main/resources/spring/metadata-consumer.xml | 35 +++++++ .../main/resources/spring/metadata-provider.xml | 38 +++++++ .../src/test/java/metadata/DemoServiceIT.java | 43 ++++++++ 19 files changed, 807 insertions(+) diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/pom.xml b/5-dubbo-spi-metadata-samples/samples-spi-metadata/pom.xml new file mode 100644 index 0000000..7ecdc7e --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/pom.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.dubbo</groupId> + <artifactId>dubbo-samples-spi</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <groupId>org.apache.dubbo</groupId> + <artifactId>samples-spi-metadata</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + <modules> + <module>samples-spi-metadata-consul</module> + <module>samples-spi-metadata-etcd</module> + <module>samples-spi-metadata-rest</module> + </modules> + + <properties> + <maven.compiler.source>17</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + +</project> \ No newline at end of file diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/pom.xml b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/pom.xml new file mode 100644 index 0000000..1b8d726 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/pom.xml @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.dubbo</groupId> + <artifactId>samples-spi-metadata</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>samples-spi-metadata-consul</artifactId> + + <properties> + <maven.compiler.source>17</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-framework-bom</artifactId> + <version>${spring.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.apache.dubbo</groupId> + <artifactId>dubbo-bom</artifactId> + <version>${dubbo.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.apache.dubbo.extensions</groupId> + <artifactId>dubbo-extensions-bom</artifactId> + <version>${spi.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.dubbo</groupId> + <artifactId>dubbo</artifactId> + <version>${dubbo.version}</version> + </dependency> + <dependency> + <groupId>org.apache.dubbo</groupId> + <artifactId>dubbo-zookeeper-curator5-spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context-support</artifactId> + </dependency> + <dependency> + <groupId>org.apache.dubbo.extensions</groupId> + <artifactId>dubbo-metadata-report-consul</artifactId> + <version>${spi.version}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + </dependency> + </dependencies> + + <profiles> + <!-- For jdk 11 above JavaEE annotation --> + <profile> + <id>javax.annotation</id> + <activation> + <jdk>[1.11,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + <version>${javax.annotation-api.version}</version> + </dependency> + </dependencies> + </profile> + </profiles> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>${maven-compiler-plugin.version}</version> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/ConsulConsumer.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/ConsulConsumer.java new file mode 100644 index 0000000..4c695fc --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/ConsulConsumer.java @@ -0,0 +1,38 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dubbo.samples.spi.metadata; + + +import org.apache.dubbo.samples.spi.metadata.api.DemoService; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + + +public class ConsulConsumer { + + public static void main(String[] args) throws InterruptedException { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/consul-consumer.xml"}); + context.start(); + DemoService demoService = context.getBean("demoService", DemoService.class); + + String hello = demoService.sayHello("world"); + System.out.println(hello); + } +} diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/ConsulProvider.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/ConsulProvider.java new file mode 100644 index 0000000..1bf8365 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/ConsulProvider.java @@ -0,0 +1,37 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dubbo.samples.spi.metadata; + + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.util.concurrent.CountDownLatch; + + +public class ConsulProvider { + + public static void main(String[] args) throws InterruptedException { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/consul-provider.xml"}); + context.start(); + + System.out.println("dubbo service started"); + new CountDownLatch(1).await(); + } +} diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/api/DemoService.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/api/DemoService.java new file mode 100644 index 0000000..4a0cb60 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/api/DemoService.java @@ -0,0 +1,26 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dubbo.samples.spi.metadata.api; + +public interface DemoService { + + String sayHello(String name); + +} diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/impl/DemoServiceImpl.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/impl/DemoServiceImpl.java new file mode 100644 index 0000000..eb326f4 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/java/org/apache/dubbo/samples/spi/metadata/impl/DemoServiceImpl.java @@ -0,0 +1,35 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dubbo.samples.spi.metadata.impl; + + +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.samples.spi.metadata.api.DemoService; + +@DubboService +public class DemoServiceImpl implements DemoService { + + @Override + public String sayHello(String name) { + return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); + } + +} diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/resources/log4j2.xml b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/resources/log4j2.xml new file mode 100644 index 0000000..69e1321 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/resources/log4j2.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<Configuration status="WARN"> + <Appenders> + <Console name="Console" target="SYSTEM_OUT" follow="true"> + <PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} %style{-|}{White} %m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" disableAnsi="false" charset="UTF-8"/> + </Console> + </Appenders> + <Loggers> + <Root level="info"> + <AppenderRef ref="Console"/> + </Root> + </Loggers> +</Configuration> diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/resources/spring/consul-consumer.xml b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/resources/spring/consul-consumer.xml new file mode 100644 index 0000000..bc89199 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/resources/spring/consul-consumer.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ + ~ 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. + ~ + --> + +<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" + xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd + http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> + <context:property-placeholder/> + + <dubbo:application name="dubbo-spi-metadata-consul-consumer"/> + + <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/> + + <dubbo:metadata-report address="consul://${consul.address:127.0.0.1}:${consul.port:8500}"/> + + <dubbo:reference id="demoService" interface="org.apache.dubbo.samples.spi.metadata.api.DemoService"/> +</beans> diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/resources/spring/consul-provider.xml b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/resources/spring/consul-provider.xml new file mode 100644 index 0000000..7234c39 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/main/resources/spring/consul-provider.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ + ~ 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. + ~ + --> + +<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" + xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd + http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> + <context:property-placeholder/> + + <dubbo:application name="dubbo-spi-metadata-consul-provider"/> + + <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/> + + <dubbo:metadata-report address="consul://${consul.address:127.0.0.1}:${consul.port:8500}"/> + + <bean id="demoService" class="org.apache.dubbo.samples.spi.metadata.impl.DemoServiceImpl"/> + + <dubbo:service interface="org.apache.dubbo.samples.spi.metadata.api.DemoService" ref="demoService"/> + +</beans> diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/test/java/metadata/DemoServiceIT.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/test/java/metadata/DemoServiceIT.java new file mode 100644 index 0000000..969503f --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-consul/src/test/java/metadata/DemoServiceIT.java @@ -0,0 +1,42 @@ +/* + * 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 metadata; + + +import org.apache.dubbo.samples.spi.metadata.api.DemoService; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "classpath*:spring/consul-consumer.xml") +public class DemoServiceIT { + @Autowired + @Qualifier("demoService") + private DemoService demoService; + + @Test + public void test() throws Exception { + Assert.assertTrue(demoService.sayHello("world").startsWith("Hello world")); + } +} diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/pom.xml b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/pom.xml new file mode 100644 index 0000000..fc05cfc --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/pom.xml @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.dubbo</groupId> + <artifactId>samples-spi-metadata</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + + <artifactId>samples-spi-metadata-etcd</artifactId> + + <properties> + <maven.compiler.source>17</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-framework-bom</artifactId> + <version>${spring.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.apache.dubbo</groupId> + <artifactId>dubbo-bom</artifactId> + <version>${dubbo.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.apache.dubbo.extensions</groupId> + <artifactId>dubbo-extensions-bom</artifactId> + <version>${spi.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.dubbo</groupId> + <artifactId>dubbo</artifactId> + <version>${dubbo.version}</version> + </dependency> + <dependency> + <groupId>org.apache.dubbo</groupId> + <artifactId>dubbo-zookeeper-curator5-spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context-support</artifactId> + </dependency> + <dependency> + <groupId>org.apache.dubbo.extensions</groupId> + <artifactId>dubbo-metadata-report-etcd</artifactId> + <version>${spi.version}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + </dependency> + </dependencies> + + <profiles> + <!-- For jdk 11 above JavaEE annotation --> + <profile> + <id>javax.annotation</id> + <activation> + <jdk>[1.11,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + <version>${javax.annotation-api.version}</version> + </dependency> + </dependencies> + </profile> + </profiles> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>${maven-compiler-plugin.version}</version> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/EtcdConsumer.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/EtcdConsumer.java new file mode 100644 index 0000000..010a9aa --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/EtcdConsumer.java @@ -0,0 +1,36 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dubbo.samples.spi.metadata; + +import org.apache.dubbo.samples.spi.metadata.api.DemoService; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + + +public class EtcdConsumer { + public static void main(String[] args) { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/metadata-consumer.xml"}); + context.start(); + DemoService demoService = context.getBean("demoService", DemoService.class); + + String hello = demoService.sayHello("world"); + System.out.println(hello); + } +} diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/EtcdProvider.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/EtcdProvider.java new file mode 100644 index 0000000..2469a6a --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/EtcdProvider.java @@ -0,0 +1,37 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dubbo.samples.spi.metadata; + + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.util.concurrent.CountDownLatch; + + +public class EtcdProvider { + + public static void main(String[] args) throws InterruptedException { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/metadata-provider.xml"}); + context.start(); + + System.out.println("dubbo service started"); + new CountDownLatch(1).await(); + } +} diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/api/DemoService.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/api/DemoService.java new file mode 100644 index 0000000..4a0cb60 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/api/DemoService.java @@ -0,0 +1,26 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dubbo.samples.spi.metadata.api; + +public interface DemoService { + + String sayHello(String name); + +} diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/impl/DemoServiceImpl.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/impl/DemoServiceImpl.java new file mode 100644 index 0000000..eb326f4 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/java/org/apache/dubbo/samples/spi/metadata/impl/DemoServiceImpl.java @@ -0,0 +1,35 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dubbo.samples.spi.metadata.impl; + + +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.samples.spi.metadata.api.DemoService; + +@DubboService +public class DemoServiceImpl implements DemoService { + + @Override + public String sayHello(String name) { + return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); + } + +} diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/resources/log4j2.xml b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/resources/log4j2.xml new file mode 100644 index 0000000..69e1321 --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/resources/log4j2.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<Configuration status="WARN"> + <Appenders> + <Console name="Console" target="SYSTEM_OUT" follow="true"> + <PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} %style{-|}{White} %m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" disableAnsi="false" charset="UTF-8"/> + </Console> + </Appenders> + <Loggers> + <Root level="info"> + <AppenderRef ref="Console"/> + </Root> + </Loggers> +</Configuration> diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/resources/spring/metadata-consumer.xml b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/resources/spring/metadata-consumer.xml new file mode 100644 index 0000000..a7957ab --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/resources/spring/metadata-consumer.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ + ~ 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. + ~ + --> + +<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" + xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd + http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> + <context:property-placeholder/> + + <dubbo:application name="dubbo-spi-metadata-etcd-consumer"/> + + <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/> + + <dubbo:metadata-report address="etcd://${etcd.address:localhost}:${etcd.port:2379}"/> + + <dubbo:reference id="demoService" interface="org.apache.dubbo.samples.spi.metadata.api.DemoService"/> +</beans> diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/resources/spring/metadata-provider.xml b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/resources/spring/metadata-provider.xml new file mode 100644 index 0000000..4ef4d2a --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/main/resources/spring/metadata-provider.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ + ~ 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. + ~ + --> + +<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" + xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd + http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> + <context:property-placeholder/> + + <dubbo:application name="dubbo-spi-metadata-etcd-provider"/> + + <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/> + + <dubbo:metadata-report protocol="etcd" address="etcd://${etcd.address:127.0.0.1}:${etcd.port:2379}"/> + + <bean id="demoService" class="org.apache.dubbo.samples.spi.metadata.impl.DemoServiceImpl"/> + + <dubbo:service interface="org.apache.dubbo.samples.spi.metadata.api.DemoService" ref="demoService"/> + +</beans> diff --git a/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/test/java/metadata/DemoServiceIT.java b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/test/java/metadata/DemoServiceIT.java new file mode 100644 index 0000000..05b6bac --- /dev/null +++ b/5-dubbo-spi-metadata-samples/samples-spi-metadata/samples-spi-metadata-etcd/src/test/java/metadata/DemoServiceIT.java @@ -0,0 +1,43 @@ +/* + * 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 metadata; + + + +import org.apache.dubbo.samples.spi.metadata.api.DemoService; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "classpath*:spring/metadata-consumer.xml") +public class DemoServiceIT { + @Autowired + @Qualifier("demoService") + private DemoService demoService; + + @Test + public void test() throws Exception { + Assert.assertTrue(demoService.sayHello("world").startsWith("Hello world")); + } +}