From b6930b2335a3727ba5f4cb2b911a3cec7728e908 Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Tue, 28 Feb 2023 19:56:36 +0800 Subject: [PATCH 01/12] add spring-boot style --- .../dubbo-samples-direct-consumer/pom.xml | 65 +++++++++++++ .../direct/DirectConsumerApplication.java | 13 +++ .../org/apache/dubbo/samples/direct/Task.java | 21 +++++ .../src/main/resources/application.yml | 24 +++++ .../src/main/resources/log4j.properties | 26 ++++++ .../dubbo-samples-direct-interface/pom.xml | 14 +++ .../samples/direct/api/DirectService.java | 5 + .../dubbo-samples-direct-provider/pom.xml | 65 +++++++++++++ .../direct/DirectProviderApplication.java | 13 +++ .../direct/impl/DirectServiceImpl.java | 19 ++++ .../src/main/resources/application.yml | 12 +++ .../src/main/resources/log4j.properties | 26 ++++++ 2-advanced/dubbo-samples-direct/pom.xml | 91 +++++++++---------- 13 files changed, 346 insertions(+), 48 deletions(-) create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/pom.xml create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/resources/log4j.properties create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/pom.xml create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/log4j.properties diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/pom.xml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/pom.xml new file mode 100644 index 0000000000..372240973b --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/pom.xml @@ -0,0 +1,65 @@ + + + dubbo-samples-direct + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + dubbo-samples-direct-consumer + + + + org.apache.dubbo + dubbo-samples-direct-interface + ${project.parent.version} + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + org.apache.dubbo + dubbo-dependencies-zookeeper + pom + + + slf4j-reload4j + org.slf4j + + + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java new file mode 100644 index 0000000000..a0fb940310 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java @@ -0,0 +1,13 @@ +package org.apache.dubbo.samples.direct; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class DirectConsumerApplication { + public static void main(String[] args) { + SpringApplication.run(DirectConsumerApplication.class,args); + } +} diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java new file mode 100644 index 0000000000..df3cac4a36 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java @@ -0,0 +1,21 @@ +package org.apache.dubbo.samples.direct; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.samples.direct.api.DirectService; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + + + +@Component +public class Task implements CommandLineRunner { + @DubboReference + private DirectService directService; + + @Override + public void run(String... args) throws Exception { + String hello = directService.sayHello("world"); + System.out.println(hello); + + } +} diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/resources/application.yml new file mode 100644 index 0000000000..933e5be5e8 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/resources/application.yml @@ -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. +dubbo: + application: + name: direct-consumer + qos-enable: false + protocol: + name: dubbo + port: -1 + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/resources/log4j.properties new file mode 100644 index 0000000000..d6ecd5ce34 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/resources/log4j.properties @@ -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. +# +# + +###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/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/pom.xml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/pom.xml new file mode 100644 index 0000000000..db7821e1b4 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/pom.xml @@ -0,0 +1,14 @@ + + + + dubbo-samples-direct + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + dubbo-samples-direct-interface + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java new file mode 100644 index 0000000000..4518bf6de0 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java @@ -0,0 +1,5 @@ +package org.apache.dubbo.samples.direct.api; + +public interface DirectService { + String sayHello(String name); +} diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml new file mode 100644 index 0000000000..50a65a819b --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml @@ -0,0 +1,65 @@ + + + dubbo-samples-direct + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + dubbo-samples-direct-provider + + + + org.apache.dubbo + dubbo-samples-direct-interface + ${project.parent.version} + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + org.apache.dubbo + dubbo-dependencies-zookeeper + pom + + + slf4j-reload4j + org.slf4j + + + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java new file mode 100644 index 0000000000..0a527e3268 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java @@ -0,0 +1,13 @@ +package org.apache.dubbo.samples.direct; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class DirectProviderApplication { + public static void main(String[] args) { + SpringApplication.run(DirectProviderApplication.class, args); + } +} diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java new file mode 100644 index 0000000000..679c5ecae5 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java @@ -0,0 +1,19 @@ +package org.apache.dubbo.samples.direct.impl; + +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.samples.direct.api.DirectService; + + +import java.text.SimpleDateFormat; +import java.util.Date; + +@DubboService +public class DirectServiceImpl implements DirectService { + @Override + public String sayHello(String name) { + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); + return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); + } +} diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml new file mode 100644 index 0000000000..0634fef8bb --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml @@ -0,0 +1,12 @@ + +dubbo: + application: + name: direct-provider + qos-enable: false + protocol: + name: dubbo + port: 20880 + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 + provider: + token: "true" \ No newline at end of file diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/log4j.properties new file mode 100644 index 0000000000..d6ecd5ce34 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/log4j.properties @@ -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. +# +# + +###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/2-advanced/dubbo-samples-direct/pom.xml b/2-advanced/dubbo-samples-direct/pom.xml index 393df29565..45c1bad409 100644 --- a/2-advanced/dubbo-samples-direct/pom.xml +++ b/2-advanced/dubbo-samples-direct/pom.xml @@ -18,30 +18,46 @@ - org.apache.dubbo - 1.0-SNAPSHOT + + + + + org.apache + apache + 23 + + 4.0.0 + org.apache.dubbo dubbo-samples-direct + 1.0-SNAPSHOT + pom Dubbo Samples Direct Dubbo Samples Direct - 1.8 - 1.8 - 3.1.6 - 4.3.29.RELEASE + 3.2.0-beta.4 4.13.1 - 3.7.0 + 2.7.8 + 1.8 + 1.8 + + dubbo-samples-direct-consumer + dubbo-samples-direct-interface + dubbo-samples-direct-provider + + + - org.springframework - spring-framework-bom - ${spring.version} + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} pom import @@ -54,10 +70,16 @@ org.apache.dubbo - dubbo-dependencies-zookeeper + dubbo-dependencies-zookeeper-curator5 ${dubbo.version} pom + + junit + junit + ${junit.version} + test + @@ -67,11 +89,6 @@ dubbo - - org.apache.dubbo - dubbo-dependencies-zookeeper - pom - junit @@ -80,41 +97,19 @@ test - - org.springframework - spring-test - test - - - - - javax.annotation - - [1.11,) - - - - javax.annotation - javax.annotation-api - 1.3.2 - - - - + - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${source.level} - ${target.level} - - - + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + From dd70251602d85f7ab7c67c2043786ea1635dbeb5 Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Tue, 28 Feb 2023 20:52:39 +0800 Subject: [PATCH 02/12] fix: add license head --- .../direct/DirectConsumerApplication.java | 18 ++++++++++++++++++ .../org/apache/dubbo/samples/direct/Task.java | 17 +++++++++++++++++ .../samples/direct/api/DirectService.java | 17 +++++++++++++++++ .../direct/DirectProviderApplication.java | 17 +++++++++++++++++ .../samples/direct/impl/DirectServiceImpl.java | 17 +++++++++++++++++ 5 files changed, 86 insertions(+) diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java index a0fb940310..6d17428545 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java @@ -1,3 +1,21 @@ +/* + * 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.direct; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java index df3cac4a36..54d297d28c 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.apache.dubbo.samples.direct; import org.apache.dubbo.config.annotation.DubboReference; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java index 4518bf6de0..9ac20e7b72 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.apache.dubbo.samples.direct.api; public interface DirectService { diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java index 0a527e3268..92a12ba7fb 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.apache.dubbo.samples.direct; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java index 679c5ecae5..a820f379f8 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.apache.dubbo.samples.direct.impl; import org.apache.dubbo.config.annotation.DubboService; From c7256738054082f167e03982eda9819be14bd84a Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Wed, 1 Mar 2023 23:24:12 +0800 Subject: [PATCH 03/12] fix: add license head in pom --- .../dubbo-samples-direct-consumer/pom.xml | 19 +++++++++++++++++++ .../dubbo-samples-direct-interface/pom.xml | 19 +++++++++++++++++++ .../dubbo-samples-direct-provider/pom.xml | 19 +++++++++++++++++++ .../src/main/resources/application.yml | 16 +++++++++++++++- 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/pom.xml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/pom.xml index 372240973b..ad32575d2b 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/pom.xml +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/pom.xml @@ -1,3 +1,22 @@ + + + + diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/pom.xml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/pom.xml index db7821e1b4..0c0a184929 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/pom.xml +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-interface/pom.xml @@ -1,3 +1,22 @@ + + + + diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml index 50a65a819b..f176402508 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml @@ -1,3 +1,22 @@ + + + + diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml index 0634fef8bb..d199377925 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml @@ -1,4 +1,18 @@ - +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. dubbo: application: name: direct-provider From e5407f9687feb893d80015674e0716a33c276d8f Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Wed, 1 Mar 2023 23:51:34 +0800 Subject: [PATCH 04/12] fix: update pom.xml --- .../dubbo-samples-direct-provider/pom.xml | 7 ++----- 2-advanced/dubbo-samples-direct/pom.xml | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml index f176402508..d1f3f96984 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/pom.xml @@ -43,7 +43,7 @@ org.apache.dubbo - dubbo-dependencies-zookeeper + dubbo-dependencies-zookeeper-curator5 pom @@ -59,10 +59,7 @@ spring-boot-starter - - org.springframework.boot - spring-boot-starter-test - + diff --git a/2-advanced/dubbo-samples-direct/pom.xml b/2-advanced/dubbo-samples-direct/pom.xml index 45c1bad409..c37a776804 100644 --- a/2-advanced/dubbo-samples-direct/pom.xml +++ b/2-advanced/dubbo-samples-direct/pom.xml @@ -19,8 +19,6 @@ 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"> - - org.apache apache From 5ee7421ecb91352930236b575990c02390f73b57 Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Sat, 4 Mar 2023 22:46:52 +0800 Subject: [PATCH 05/12] feat: add two group of DirectService --- .../case-configuration.yml | 33 ++++++-- .../{ => api}/DirectConsumerApplication.java | 2 +- .../dubbo/samples/direct/{ => api}/Task.java | 9 ++- .../{ => api}/DirectProviderApplication.java | 2 +- .../{ => api}/impl/DirectServiceImpl.java | 4 +- .../src/main/resources/application.yml | 4 +- 2-advanced/dubbo-samples-direct/pom.xml | 2 +- .../dubbo/samples/direct/DirectConsumer.java | 36 --------- .../dubbo/samples/direct/DirectProvider.java | 35 --------- .../samples/direct/api/DirectService.java | 27 ------- .../direct/impl/DirectServiceImpl.java | 36 --------- .../src/main/resources/log4j.properties | 26 ------- .../spring/dubbo-direct-consumer.xml | 30 -------- .../spring/dubbo-direct-provider.xml | 40 ---------- .../dubbo/samples/direct/DirectServiceIT.java | 77 ------------------- 15 files changed, 40 insertions(+), 323 deletions(-) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/{ => api}/DirectConsumerApplication.java (96%) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/{ => api}/Task.java (83%) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/{ => api}/DirectProviderApplication.java (96%) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/{ => api}/impl/DirectServiceImpl.java (91%) delete mode 100644 2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/DirectConsumer.java delete mode 100644 2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/DirectProvider.java delete mode 100644 2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java delete mode 100644 2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java delete mode 100644 2-advanced/dubbo-samples-direct/src/main/resources/log4j.properties delete mode 100644 2-advanced/dubbo-samples-direct/src/main/resources/spring/dubbo-direct-consumer.xml delete mode 100644 2-advanced/dubbo-samples-direct/src/main/resources/spring/dubbo-direct-provider.xml delete mode 100644 2-advanced/dubbo-samples-direct/src/test/java/org/apache/dubbo/samples/direct/DirectServiceIT.java diff --git a/2-advanced/dubbo-samples-direct/case-configuration.yml b/2-advanced/dubbo-samples-direct/case-configuration.yml index 8f5751582a..e6d08a7d01 100644 --- a/2-advanced/dubbo-samples-direct/case-configuration.yml +++ b/2-advanced/dubbo-samples-direct/case-configuration.yml @@ -14,9 +14,32 @@ # See the License for the specific language governing permissions and # limitations under the License. -from: app-external-zookeeper.yml +services: + zookeeper: + image: zookeeper:latest + + provider: + type: app + basedir: dubbo-samples-direct-provider + mainClass: org.apache.dubbo.samples.direct.DirectProviderApplication + systemProps: + - zookeeper.address=zookeeper + waitPortsBeforeRun: + - zookeeper:2181 + checkPorts: + - 20880 + checkLog: "Current Spring Boot Application is await..." + + test: + type: test + basedir: dubbo-samples-direct-consumer + tests: + - "**/*IT.class" + systemProps: + - zookeeper.address=zookeeper + waitPortsBeforeRun: + - zookeeper:2181 + - provider:20880 + depends_on: + - provider -props: - project_name: dubbo-samples-direct - main_class: org.apache.dubbo.samples.direct.DirectProvider - dubbo_port: 20880 \ No newline at end of file diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/DirectConsumerApplication.java similarity index 96% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/DirectConsumerApplication.java index 6d17428545..ed32a1cda0 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/DirectConsumerApplication.java @@ -16,7 +16,7 @@ */ -package org.apache.dubbo.samples.direct; +package org.apache.dubbo.samples.direct.api; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java similarity index 83% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java index 54d297d28c..2cceb26952 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.dubbo.samples.direct; +package org.apache.dubbo.samples.direct.api; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.samples.direct.api.DirectService; +import org.apache.dubbo.config.annotation.Method; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; @@ -26,7 +26,10 @@ @Component public class Task implements CommandLineRunner { - @DubboReference + @DubboReference(interfaceClass = DirectService.class, + check = false, + group = "test", + version = "1.0.0-daily") private DirectService directService; @Override diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/DirectProviderApplication.java similarity index 96% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/DirectProviderApplication.java index 92a12ba7fb..6f006c2d1b 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/DirectProviderApplication.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.dubbo.samples.direct; +package org.apache.dubbo.samples.direct.api; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl.java similarity index 91% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl.java index a820f379f8..9b9bacbdb0 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.dubbo.samples.direct.impl; +package org.apache.dubbo.samples.direct.api.impl; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.rpc.RpcContext; @@ -25,7 +25,7 @@ import java.text.SimpleDateFormat; import java.util.Date; -@DubboService +@DubboService(interfaceClass = DirectService.class,group = "test",version = "1.0.0-daily") public class DirectServiceImpl implements DirectService { @Override public String sayHello(String name) { diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml index d199377925..727c1eaebe 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/resources/application.yml @@ -19,8 +19,6 @@ dubbo: qos-enable: false protocol: name: dubbo - port: 20880 + port: -1 registry: address: zookeeper://${zookeeper.address:127.0.0.1}:2181 - provider: - token: "true" \ No newline at end of file diff --git a/2-advanced/dubbo-samples-direct/pom.xml b/2-advanced/dubbo-samples-direct/pom.xml index c37a776804..d0c52845b0 100644 --- a/2-advanced/dubbo-samples-direct/pom.xml +++ b/2-advanced/dubbo-samples-direct/pom.xml @@ -36,7 +36,7 @@ Dubbo Samples Direct - 3.2.0-beta.4 + 3.2.0-beta.6-SNAPSHOT 4.13.1 2.7.8 1.8 diff --git a/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/DirectConsumer.java b/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/DirectConsumer.java deleted file mode 100644 index 5d62854b42..0000000000 --- a/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/DirectConsumer.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * 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.direct; - -import org.apache.dubbo.samples.direct.api.DirectService; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - - -public class DirectConsumer { - - public static void main(String[] args) { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-direct-consumer.xml"); - context.start(); - DirectService directService = (DirectService) context.getBean("directService"); - String hello = directService.sayHello("world"); - System.out.println(hello); - } -} diff --git a/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/DirectProvider.java b/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/DirectProvider.java deleted file mode 100644 index 5a22e50678..0000000000 --- a/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/DirectProvider.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * 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.direct; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.util.concurrent.CountDownLatch; - - -public class DirectProvider { - - public static void main(String[] args) throws Exception { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-direct-provider.xml"); - context.start(); - System.out.println("dubbo service started"); - new CountDownLatch(1).await(); - } -} diff --git a/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java b/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java deleted file mode 100644 index a65e47990f..0000000000 --- a/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/api/DirectService.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * - * 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.direct.api; - - -public interface DirectService { - - String sayHello(String name); - -} diff --git a/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java b/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java deleted file mode 100644 index 2a4e0c6904..0000000000 --- a/2-advanced/dubbo-samples-direct/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * 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.direct.impl; - -import org.apache.dubbo.rpc.RpcContext; -import org.apache.dubbo.samples.direct.api.DirectService; - -import java.text.SimpleDateFormat; -import java.util.Date; - - -public class DirectServiceImpl implements DirectService { - - public String sayHello(String name) { - System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + - name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); - return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); - } -} diff --git a/2-advanced/dubbo-samples-direct/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-direct/src/main/resources/log4j.properties deleted file mode 100644 index d6ecd5ce34..0000000000 --- a/2-advanced/dubbo-samples-direct/src/main/resources/log4j.properties +++ /dev/null @@ -1,26 +0,0 @@ -# -# -# 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/2-advanced/dubbo-samples-direct/src/main/resources/spring/dubbo-direct-consumer.xml b/2-advanced/dubbo-samples-direct/src/main/resources/spring/dubbo-direct-consumer.xml deleted file mode 100644 index 82a6b93be2..0000000000 --- a/2-advanced/dubbo-samples-direct/src/main/resources/spring/dubbo-direct-consumer.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - diff --git a/2-advanced/dubbo-samples-direct/src/main/resources/spring/dubbo-direct-provider.xml b/2-advanced/dubbo-samples-direct/src/main/resources/spring/dubbo-direct-provider.xml deleted file mode 100644 index 3f9ab40408..0000000000 --- a/2-advanced/dubbo-samples-direct/src/main/resources/spring/dubbo-direct-provider.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/2-advanced/dubbo-samples-direct/src/test/java/org/apache/dubbo/samples/direct/DirectServiceIT.java b/2-advanced/dubbo-samples-direct/src/test/java/org/apache/dubbo/samples/direct/DirectServiceIT.java deleted file mode 100644 index 539bdd0bfd..0000000000 --- a/2-advanced/dubbo-samples-direct/src/test/java/org/apache/dubbo/samples/direct/DirectServiceIT.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.direct; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ReferenceConfig; -import org.apache.dubbo.rpc.service.GenericService; -import org.apache.dubbo.samples.direct.api.DirectService; - -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath*:/spring/dubbo-direct-consumer.xml"}) -public class DirectServiceIT { - private static String providerAddress = System.getProperty("dubbo.address", "localhost"); - - @Autowired - private DirectService directService; - - @Test - public void testXml() throws Exception { - Assert.assertTrue(directService.sayHello("dubbo").startsWith("Hello dubbo")); - } - - @Test - public void testGeneric() throws Exception { - ApplicationConfig application = new ApplicationConfig(); - application.setName("direct-consumer"); - ReferenceConfig reference = new ReferenceConfig<>(); - reference.setUrl("dubbo://" + providerAddress + ":20880/" + DirectService.class.getName()); - reference.setVersion("1.0.0-daily"); - reference.setGroup("test2"); - reference.setGeneric(true); - reference.setApplication(application); - reference.setInterface(DirectService.class.getName()); - GenericService genericService = reference.get(); - Object obj = genericService.$invoke("sayHello", new String[]{String.class.getName()}, new Object[]{ "generic" }); - String str = (String) obj; - TestCase.assertTrue(str.startsWith("Hello generic")); - } - - @Test - public void testApi() throws Exception { - ApplicationConfig application = new ApplicationConfig(); - application.setName("direct-consumer"); - ReferenceConfig reference = new ReferenceConfig<>(); - reference.setUrl("dubbo://" + providerAddress + ":20880/" + DirectService.class.getName()); - reference.setVersion("1.0.0-daily"); - reference.setGroup("test3"); - reference.setApplication(application); - reference.setInterface(DirectService.class.getName()); - DirectService service = reference.get(); - String result = service.sayHello("api"); - TestCase.assertTrue(result.startsWith("Hello api")); - } -} From 2d9da6cbabee8ffc8489959c94ecff3a0a1c2e3a Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Sun, 5 Mar 2023 15:27:03 +0800 Subject: [PATCH 06/12] feat: add other serviceImpl --- .../direct/api/impl/DirectServiceImpl2.java | 35 +++++++++++++++++++ .../direct/api/impl/DirectServiceImpl3.java | 35 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl2.java create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl3.java diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl2.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl2.java new file mode 100644 index 0000000000..f3bdda5b6b --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl2.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.direct.api.impl; + +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.samples.direct.api.DirectService; + +import java.text.SimpleDateFormat; +import java.util.Date; + +@DubboService(interfaceClass = DirectService.class,group = "test2",version = "1.0.0-daily") +public class DirectServiceImpl2 implements DirectService { + @Override + public String sayHello(String name) { + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); + return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); + } +} diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl3.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl3.java new file mode 100644 index 0000000000..617d96d9ad --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl3.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.direct.api.impl; + +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.samples.direct.api.DirectService; + +import java.text.SimpleDateFormat; +import java.util.Date; + +@DubboService(interfaceClass = DirectService.class,group = "test3",version = "1.0.0-daily") +public class DirectServiceImpl3 implements DirectService { + @Override + public String sayHello(String name) { + System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); + return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); + } +} From ebfa1119a1d071dd973c63942e7e77ce53523a13 Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Sun, 5 Mar 2023 15:27:47 +0800 Subject: [PATCH 07/12] update: update test --- .../samples/direct/api/DirectServiceIT.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/api/DirectServiceIT.java diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/api/DirectServiceIT.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/api/DirectServiceIT.java new file mode 100644 index 0000000000..b844b3cc7e --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/api/DirectServiceIT.java @@ -0,0 +1,81 @@ +/* + * 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.direct.api; + +import junit.framework.TestCase; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.rpc.service.GenericService; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest +@RunWith(SpringRunner.class) +public class DirectServiceIT { + private static String providerAddress = System.getProperty("dubbo.address", "localhost"); + + @DubboReference(interfaceClass = DirectService.class, + check = false, + group = "test", + version = "1.0.0-daily") + private DirectService directService; + + + + @Test + public void testXml() throws Exception { + Assert.assertTrue(directService.sayHello("dubbo").startsWith("Hello dubbo")); + } + + @Test + public void testGeneric() throws Exception { + ApplicationConfig application = new ApplicationConfig(); + application.setName("direct-consumer"); + System.out.println(application.getClass()); + ReferenceConfig reference = new ReferenceConfig<>(); + reference.setUrl("dubbo://" + providerAddress + ":20880/" + DirectService.class.getName()); + reference.setVersion("1.0.0-daily"); + reference.setGroup("test2"); + reference.setGeneric(true); + reference.setApplication(application); + reference.setInterface(DirectService.class.getName()); + GenericService genericService = reference.get(); + Object obj = genericService.$invoke("sayHello", new String[]{String.class.getName()}, new Object[]{ "generic" }); + String str = (String) obj; + TestCase.assertTrue(str.startsWith("Hello generic")); + } + + @Test + public void testApi() throws Exception { + ApplicationConfig application = new ApplicationConfig(); + application.setName("direct-consumer"); + ReferenceConfig reference = new ReferenceConfig<>(); + reference.setUrl("dubbo://" + providerAddress + ":20880/" + DirectService.class.getName()); + reference.setVersion("1.0.0-daily"); + reference.setGroup("test3"); + reference.setApplication(application); + reference.setInterface(DirectService.class.getName()); + DirectService service = reference.get(); + String result = service.sayHello("api"); + TestCase.assertTrue(result.startsWith("Hello api")); + } +} From 047f2490912c5b0ec5783c2d22da782aa621a41f Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Mon, 6 Mar 2023 22:27:14 +0800 Subject: [PATCH 08/12] update: update case-configuration.yml --- .../case-configuration.yml | 27 ++++++++++--------- .../apache/dubbo/samples/direct/api/Task.java | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/2-advanced/dubbo-samples-direct/case-configuration.yml b/2-advanced/dubbo-samples-direct/case-configuration.yml index e6d08a7d01..b82861167a 100644 --- a/2-advanced/dubbo-samples-direct/case-configuration.yml +++ b/2-advanced/dubbo-samples-direct/case-configuration.yml @@ -15,31 +15,32 @@ # limitations under the License. services: - zookeeper: - image: zookeeper:latest - provider: + direct-provider: type: app basedir: dubbo-samples-direct-provider mainClass: org.apache.dubbo.samples.direct.DirectProviderApplication - systemProps: - - zookeeper.address=zookeeper - waitPortsBeforeRun: - - zookeeper:2181 - checkPorts: - - 20880 - checkLog: "Current Spring Boot Application is await..." +# systemProps: +# - zookeeper.address=zookeeper +# waitPortsBeforeRun: +# - zookeeper:2181 +# checkPorts: +# - 20880 +# checkLog: "Current Spring Boot Application is await..." - test: + direct-consumer: type: test basedir: dubbo-samples-direct-consumer tests: - "**/*IT.class" systemProps: - zookeeper.address=zookeeper + - zookeeper.port=2181 + - dubbo.address=direct-provider + - dubbo.port=20880 waitPortsBeforeRun: - zookeeper:2181 - - provider:20880 + - direct-provider:20880 depends_on: - - provider + - direct-provider diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java index 2cceb26952..837af315fb 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java @@ -28,7 +28,7 @@ public class Task implements CommandLineRunner { @DubboReference(interfaceClass = DirectService.class, check = false, - group = "test", + group = "*", version = "1.0.0-daily") private DirectService directService; From c974b4168b7be050d88f2f09402d72c914ac7097 Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Mon, 6 Mar 2023 22:44:53 +0800 Subject: [PATCH 09/12] update: update case-configuration.yml --- 2-advanced/dubbo-samples-direct/case-configuration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-advanced/dubbo-samples-direct/case-configuration.yml b/2-advanced/dubbo-samples-direct/case-configuration.yml index b82861167a..78cb951002 100644 --- a/2-advanced/dubbo-samples-direct/case-configuration.yml +++ b/2-advanced/dubbo-samples-direct/case-configuration.yml @@ -19,7 +19,7 @@ services: direct-provider: type: app basedir: dubbo-samples-direct-provider - mainClass: org.apache.dubbo.samples.direct.DirectProviderApplication + mainClass: org.apache.dubbo.samples.direct.api.DirectProviderApplication # systemProps: # - zookeeper.address=zookeeper # waitPortsBeforeRun: From 28f4274aa956973a14b4836b91f3a2654fa93825 Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Mon, 6 Mar 2023 22:53:15 +0800 Subject: [PATCH 10/12] update: update case-configuration.yml --- 2-advanced/dubbo-samples-direct/case-configuration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2-advanced/dubbo-samples-direct/case-configuration.yml b/2-advanced/dubbo-samples-direct/case-configuration.yml index 78cb951002..26ffbd0f5a 100644 --- a/2-advanced/dubbo-samples-direct/case-configuration.yml +++ b/2-advanced/dubbo-samples-direct/case-configuration.yml @@ -34,12 +34,12 @@ services: tests: - "**/*IT.class" systemProps: - - zookeeper.address=zookeeper + - zookeeper.address=direct-provider - zookeeper.port=2181 - dubbo.address=direct-provider - dubbo.port=20880 waitPortsBeforeRun: - - zookeeper:2181 + - cache-provider:2181 - direct-provider:20880 depends_on: - direct-provider From de489c0c7df3fa31f5a1e89ccb0dd5b7579fc290 Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Tue, 7 Mar 2023 00:21:05 +0800 Subject: [PATCH 11/12] update: update case-configuration.yml --- 2-advanced/dubbo-samples-direct/case-configuration.yml | 5 ++--- .../samples/direct/{api => }/DirectConsumerApplication.java | 2 +- .../org/apache/dubbo/samples/direct/{api => }/Task.java | 6 +++--- .../dubbo/samples/direct/{api => }/DirectServiceIT.java | 5 ++++- .../samples/direct/{api => }/DirectProviderApplication.java | 2 +- .../samples/direct/{api => }/impl/DirectServiceImpl.java | 3 +-- .../samples/direct/{api => }/impl/DirectServiceImpl2.java | 2 +- .../samples/direct/{api => }/impl/DirectServiceImpl3.java | 2 +- 8 files changed, 14 insertions(+), 13 deletions(-) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/{api => }/DirectConsumerApplication.java (96%) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/{api => }/Task.java (91%) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/{api => }/DirectServiceIT.java (97%) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/{api => }/DirectProviderApplication.java (96%) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/{api => }/impl/DirectServiceImpl.java (96%) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/{api => }/impl/DirectServiceImpl2.java (96%) rename 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/{api => }/impl/DirectServiceImpl3.java (96%) diff --git a/2-advanced/dubbo-samples-direct/case-configuration.yml b/2-advanced/dubbo-samples-direct/case-configuration.yml index 26ffbd0f5a..cbd378da4c 100644 --- a/2-advanced/dubbo-samples-direct/case-configuration.yml +++ b/2-advanced/dubbo-samples-direct/case-configuration.yml @@ -19,7 +19,7 @@ services: direct-provider: type: app basedir: dubbo-samples-direct-provider - mainClass: org.apache.dubbo.samples.direct.api.DirectProviderApplication + mainClass: org.apache.dubbo.samples.direct.DirectProviderApplication # systemProps: # - zookeeper.address=zookeeper # waitPortsBeforeRun: @@ -27,7 +27,6 @@ services: # checkPorts: # - 20880 # checkLog: "Current Spring Boot Application is await..." - direct-consumer: type: test basedir: dubbo-samples-direct-consumer @@ -39,7 +38,7 @@ services: - dubbo.address=direct-provider - dubbo.port=20880 waitPortsBeforeRun: - - cache-provider:2181 + - direct-provider:2181 - direct-provider:20880 depends_on: - direct-provider diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/DirectConsumerApplication.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java similarity index 96% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/DirectConsumerApplication.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java index ed32a1cda0..6d17428545 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/DirectConsumerApplication.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/DirectConsumerApplication.java @@ -16,7 +16,7 @@ */ -package org.apache.dubbo.samples.direct.api; +package org.apache.dubbo.samples.direct; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java similarity index 91% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java index 837af315fb..b909465337 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/api/Task.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/main/java/org/apache/dubbo/samples/direct/Task.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.dubbo.samples.direct.api; +package org.apache.dubbo.samples.direct; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.config.annotation.Method; +import org.apache.dubbo.samples.direct.api.DirectService; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; @@ -28,7 +28,7 @@ public class Task implements CommandLineRunner { @DubboReference(interfaceClass = DirectService.class, check = false, - group = "*", + group = "test", version = "1.0.0-daily") private DirectService directService; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/api/DirectServiceIT.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/DirectServiceIT.java similarity index 97% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/api/DirectServiceIT.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/DirectServiceIT.java index b844b3cc7e..0f93040042 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/api/DirectServiceIT.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-consumer/src/test/java/org/apache/dubbo/samples/direct/DirectServiceIT.java @@ -15,13 +15,14 @@ * limitations under the License. */ -package org.apache.dubbo.samples.direct.api; +package org.apache.dubbo.samples.direct; import junit.framework.TestCase; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.rpc.service.GenericService; +import org.apache.dubbo.samples.direct.api.DirectService; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,11 +44,13 @@ public class DirectServiceIT { @Test public void testXml() throws Exception { + Assert.assertTrue(directService.sayHello("dubbo").startsWith("Hello dubbo")); } @Test public void testGeneric() throws Exception { + ApplicationConfig application = new ApplicationConfig(); application.setName("direct-consumer"); System.out.println(application.getClass()); diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/DirectProviderApplication.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java similarity index 96% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/DirectProviderApplication.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java index 6f006c2d1b..92a12ba7fb 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/DirectProviderApplication.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.dubbo.samples.direct.api; +package org.apache.dubbo.samples.direct; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java similarity index 96% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java index 9b9bacbdb0..eee4d8a028 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl.java @@ -15,13 +15,12 @@ * limitations under the License. */ -package org.apache.dubbo.samples.direct.api.impl; +package org.apache.dubbo.samples.direct.impl; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.samples.direct.api.DirectService; - import java.text.SimpleDateFormat; import java.util.Date; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl2.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl2.java similarity index 96% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl2.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl2.java index f3bdda5b6b..959f25af84 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl2.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl2.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.dubbo.samples.direct.api.impl; +package org.apache.dubbo.samples.direct.impl; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.rpc.RpcContext; diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl3.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl3.java similarity index 96% rename from 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl3.java rename to 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl3.java index 617d96d9ad..e5e26166b2 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/api/impl/DirectServiceImpl3.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/impl/DirectServiceImpl3.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.dubbo.samples.direct.api.impl; +package org.apache.dubbo.samples.direct.impl; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.rpc.RpcContext; From 311fc91065f263c382877756d26856e1f219af1d Mon Sep 17 00:00:00 2001 From: Wesley <2915519956@qq.com> Date: Tue, 7 Mar 2023 09:47:40 +0800 Subject: [PATCH 12/12] add:add EmbeddedZookeeper --- .../direct/DirectProviderApplication.java | 2 + .../samples/direct/EmbeddedZooKeeper.java | 225 ++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/EmbeddedZooKeeper.java diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java index 92a12ba7fb..02f56f6d0a 100644 --- a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/DirectProviderApplication.java @@ -24,7 +24,9 @@ @SpringBootApplication @EnableDubbo public class DirectProviderApplication { + public static void main(String[] args) { + new EmbeddedZooKeeper(2181,false).start(); SpringApplication.run(DirectProviderApplication.class, args); } } diff --git a/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/EmbeddedZooKeeper.java new file mode 100644 index 0000000000..e050bb6757 --- /dev/null +++ b/2-advanced/dubbo-samples-direct/dubbo-samples-direct-provider/src/main/java/org/apache/dubbo/samples/direct/EmbeddedZooKeeper.java @@ -0,0 +1,225 @@ +/* + * Copyright 2014 the original author or authors. + * + * 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 org.apache.dubbo.samples.direct; + +import org.apache.zookeeper.server.ServerConfig; +import org.apache.zookeeper.server.ZooKeeperServerMain; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.SmartLifecycle; +import org.springframework.util.ErrorHandler; +import org.springframework.util.SocketUtils; +import java.io.File; +import java.lang.reflect.Method; +import java.util.Properties; +import java.util.UUID; +/** + * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java + * + * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper. + * + * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for + * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication} + * + * @author Patrick Peralta + * @author Mark Fisher + * @author David Turanski + */ +public class EmbeddedZooKeeper implements SmartLifecycle { + /** + * Logger. + */ + private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class); + /** + * ZooKeeper client port. This will be determined dynamically upon startup. + */ + private final int clientPort; + /** + * Whether to auto-start. Default is true. + */ + private boolean autoStartup = true; + /** + * Lifecycle phase. Default is 0. + */ + private int phase = 0; + /** + * Thread for running the ZooKeeper server. + */ + private volatile Thread zkServerThread; + /** + * ZooKeeper server. + */ + private volatile ZooKeeperServerMain zkServer; + /** + * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. + */ + private ErrorHandler errorHandler; + private boolean daemon = true; + /** + * Construct an EmbeddedZooKeeper with a random port. + */ + public EmbeddedZooKeeper() { + clientPort = SocketUtils.findAvailableTcpPort(); + } + /** + * Construct an EmbeddedZooKeeper with the provided port. + * + * @param clientPort port for ZooKeeper server to bind to + */ + public EmbeddedZooKeeper(int clientPort, boolean daemon) { + this.clientPort = clientPort; + this.daemon = daemon; + } + /** + * Returns the port that clients should use to connect to this embedded server. + * + * @return dynamically determined client port + */ + public int getClientPort() { + return this.clientPort; + } + /** + * Specify whether to start automatically. Default is true. + * + * @param autoStartup whether to start automatically + */ + public void setAutoStartup(boolean autoStartup) { + this.autoStartup = autoStartup; + } + /** + * {@inheritDoc} + */ + @Override + public boolean isAutoStartup() { + return this.autoStartup; + } + /** + * Specify the lifecycle phase for the embedded server. + * + * @param phase the lifecycle phase + */ + public void setPhase(int phase) { + this.phase = phase; + } + /** + * {@inheritDoc} + */ + @Override + public int getPhase() { + return this.phase; + } + /** + * {@inheritDoc} + */ + @Override + public boolean isRunning() { + return (zkServerThread != null); + } + /** + * Start the ZooKeeper server in a background thread. + *

+ * Register an error handler via {@link #setErrorHandler} in order to handle + * any exceptions thrown during startup or execution. + */ + @Override + public synchronized void start() { + if (zkServerThread == null) { + zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter"); + zkServerThread.setDaemon(daemon); + zkServerThread.start(); + } + } + /** + * Shutdown the ZooKeeper server. + */ + @Override + public synchronized void stop() { + if (zkServerThread != null) { + // The shutdown method is protected...thus this hack to invoke it. + // This will log an exception on shutdown; see + // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details. + try { + Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown"); + shutdown.setAccessible(true); + shutdown.invoke(zkServer); + } + catch (Exception e) { + throw new RuntimeException(e); + } + // It is expected that the thread will exit after + // the server is shutdown; this will block until + // the shutdown is complete. + try { + zkServerThread.join(5000); + zkServerThread = null; + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + logger.warn("Interrupted while waiting for embedded ZooKeeper to exit"); + // abandoning zk thread + zkServerThread = null; + } + } + } + /** + * Stop the server if running and invoke the callback when complete. + */ + @Override + public void stop(Runnable callback) { + stop(); + callback.run(); + } + /** + * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none + * is provided, only error-level logging will occur. + * + * @param errorHandler the {@link ErrorHandler} to be invoked + */ + public void setErrorHandler(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } + /** + * Runnable implementation that starts the ZooKeeper server. + */ + private class ServerRunnable implements Runnable { + @Override + public void run() { + try { + Properties properties = new Properties(); + File file = new File(System.getProperty("java.io.tmpdir") + + File.separator + UUID.randomUUID()); + file.deleteOnExit(); + properties.setProperty("dataDir", file.getAbsolutePath()); + properties.setProperty("clientPort", String.valueOf(clientPort)); + QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); + quorumPeerConfig.parseProperties(properties); + zkServer = new ZooKeeperServerMain(); + ServerConfig configuration = new ServerConfig(); + configuration.readFrom(quorumPeerConfig); + zkServer.runFromConfig(configuration); + } + catch (Exception e) { + if (errorHandler != null) { + errorHandler.handleError(e); + } + else { + logger.error("Exception running embedded ZooKeeper", e); + } + } + } + } +} \ No newline at end of file