From f50478a6194c17ef429e36c0916f7de6c56cd910 Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Wed, 1 Mar 2023 11:02:56 +0800 Subject: [PATCH 01/14] springboot style --- .../dubbo-samples-callback-consumer/pom.xml | 76 ++++++ .../consumer/ConsumerApplication.java} | 23 +- .../samples/callback/consumer/Task.java} | 23 +- .../src/main/resources/application.yml | 25 ++ .../src/main/resources/log4j.properties | 0 .../dubbo-samples-callback-interface/pom.xml | 30 +++ .../callback/api/CallbackListener.java | 0 .../samples/callback/api/CallbackService.java | 0 .../dubbo-samples-callback-provider/pom.xml | 76 ++++++ .../provider}/CallbackServiceImpl.java | 6 +- .../provider/ProviderApplication.java | 34 +++ .../src/main/resources/application.yml | 26 ++ .../src/main/resources/log4j.properties | 26 ++ 2-advanced/dubbo-samples-callback/pom.xml | 76 +++--- .../samples/callback/EmbeddedZooKeeper.java | 255 ------------------ .../resources/spring/callback-consumer.xml | 32 --- .../resources/spring/callback-provider.xml | 43 --- 17 files changed, 359 insertions(+), 392 deletions(-) create mode 100644 2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/pom.xml rename 2-advanced/dubbo-samples-callback/{src/main/java/org/apache/dubbo/samples/callback/CallbackProvider.java => dubbo-samples-callback-consumer/src/main/java/org/apache/dubbo/samples/callback/consumer/ConsumerApplication.java} (60%) rename 2-advanced/dubbo-samples-callback/{src/main/java/org/apache/dubbo/samples/callback/CallbackConsumer.java => dubbo-samples-callback-consumer/src/main/java/org/apache/dubbo/samples/callback/consumer/Task.java} (66%) create mode 100644 2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/resources/application.yml rename 2-advanced/dubbo-samples-callback/{ => dubbo-samples-callback-consumer}/src/main/resources/log4j.properties (100%) create mode 100644 2-advanced/dubbo-samples-callback/dubbo-samples-callback-interface/pom.xml rename 2-advanced/dubbo-samples-callback/{ => dubbo-samples-callback-interface}/src/main/java/org/apache/dubbo/samples/callback/api/CallbackListener.java (100%) rename 2-advanced/dubbo-samples-callback/{ => dubbo-samples-callback-interface}/src/main/java/org/apache/dubbo/samples/callback/api/CallbackService.java (100%) create mode 100644 2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/pom.xml rename 2-advanced/dubbo-samples-callback/{src/main/java/org/apache/dubbo/samples/callback/impl => dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider}/CallbackServiceImpl.java (86%) create mode 100644 2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/ProviderApplication.java create mode 100644 2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/resources/log4j.properties delete mode 100644 2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/EmbeddedZooKeeper.java delete mode 100644 2-advanced/dubbo-samples-callback/src/main/resources/spring/callback-consumer.xml delete mode 100644 2-advanced/dubbo-samples-callback/src/main/resources/spring/callback-provider.xml diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/pom.xml b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/pom.xml new file mode 100644 index 0000000000..a2ffa4c636 --- /dev/null +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/pom.xml @@ -0,0 +1,76 @@ + + + + dubbo-samples-callback + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-samples-callback-consumer + + + + org.apache.dubbo + dubbo-samples-callback-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-maven-plugin + + + + repackage + + + + + + + + diff --git a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/CallbackProvider.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/java/org/apache/dubbo/samples/callback/consumer/ConsumerApplication.java similarity index 60% rename from 2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/CallbackProvider.java rename to 2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/java/org/apache/dubbo/samples/callback/consumer/ConsumerApplication.java index 94622533ab..7425e14e23 100644 --- a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/CallbackProvider.java +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/java/org/apache/dubbo/samples/callback/consumer/ConsumerApplication.java @@ -17,21 +17,18 @@ * */ -package org.apache.dubbo.samples.callback; +package org.apache.dubbo.samples.callback.consumer; -import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; -import java.util.concurrent.CountDownLatch; +@SpringBootApplication +@EnableDubbo +public class ConsumerApplication { -public class CallbackProvider { - - public static void main(String[] args) throws Exception { - new EmbeddedZooKeeper(2181, false).start(); - - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/callback-provider.xml"); - context.start(); - - System.out.println("dubbo service started"); - new CountDownLatch(1).await(); + public static void main(String[] args) { + SpringApplication.run(ConsumerApplication.class, args); } + } diff --git a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/CallbackConsumer.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/java/org/apache/dubbo/samples/callback/consumer/Task.java similarity index 66% rename from 2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/CallbackConsumer.java rename to 2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/java/org/apache/dubbo/samples/callback/consumer/Task.java index d9d4e00a76..5924abb669 100644 --- a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/CallbackConsumer.java +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/java/org/apache/dubbo/samples/callback/consumer/Task.java @@ -17,20 +17,21 @@ * */ -package org.apache.dubbo.samples.callback; +package org.apache.dubbo.samples.callback.consumer; +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.samples.callback.api.CallbackListener; import org.apache.dubbo.samples.callback.api.CallbackService; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; -import org.springframework.context.support.ClassPathXmlApplicationContext; -public class CallbackConsumer { - - public static void main(String[] args) throws Exception { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/callback-consumer.xml"); - context.start(); - - CallbackService callbackService = context.getBean("callbackService", CallbackService.class); - callbackService.addListener("foo.bar", msg -> System.out.println("callback:" + msg)); +@Component +public class Task implements CommandLineRunner { + @DubboReference + private CallbackService callbackService; + @Override + public void run(String... args) { + callbackService.addListener("foo.bar", msg -> System.out.println(msg)); } - } diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/resources/application.yml new file mode 100644 index 0000000000..039e72f2cb --- /dev/null +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/resources/application.yml @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +dubbo: + application: + name: callback-consumer + qos-enable: false + protocol: + name: dubbo + port: -1 + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 \ No newline at end of file diff --git a/2-advanced/dubbo-samples-callback/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/resources/log4j.properties similarity index 100% rename from 2-advanced/dubbo-samples-callback/src/main/resources/log4j.properties rename to 2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/main/resources/log4j.properties diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-interface/pom.xml b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-interface/pom.xml new file mode 100644 index 0000000000..2ccac73058 --- /dev/null +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-interface/pom.xml @@ -0,0 +1,30 @@ + + + + dubbo-samples-callback + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-samples-callback-interface + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/api/CallbackListener.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-interface/src/main/java/org/apache/dubbo/samples/callback/api/CallbackListener.java similarity index 100% rename from 2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/api/CallbackListener.java rename to 2-advanced/dubbo-samples-callback/dubbo-samples-callback-interface/src/main/java/org/apache/dubbo/samples/callback/api/CallbackListener.java diff --git a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/api/CallbackService.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-interface/src/main/java/org/apache/dubbo/samples/callback/api/CallbackService.java similarity index 100% rename from 2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/api/CallbackService.java rename to 2-advanced/dubbo-samples-callback/dubbo-samples-callback-interface/src/main/java/org/apache/dubbo/samples/callback/api/CallbackService.java diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/pom.xml b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/pom.xml new file mode 100644 index 0000000000..21b576f3cc --- /dev/null +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/pom.xml @@ -0,0 +1,76 @@ + + + + dubbo-samples-callback + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-samples-callback-provider + + + + org.apache.dubbo + dubbo-samples-callback-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-maven-plugin + + + + repackage + + + + + + + + diff --git a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/impl/CallbackServiceImpl.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/CallbackServiceImpl.java similarity index 86% rename from 2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/impl/CallbackServiceImpl.java rename to 2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/CallbackServiceImpl.java index df7201133d..ab903953ea 100644 --- a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/impl/CallbackServiceImpl.java +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/CallbackServiceImpl.java @@ -17,8 +17,11 @@ * */ -package org.apache.dubbo.samples.callback.impl; +package org.apache.dubbo.samples.callback.provider; +import org.apache.dubbo.config.annotation.Argument; +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.samples.callback.api.CallbackListener; import org.apache.dubbo.samples.callback.api.CallbackService; @@ -27,6 +30,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +@DubboService(token = "true", connections = 1, callbacks = 1000, methods = @Method(name = "addListener", arguments = @Argument(index = 1, callback = true))) public class CallbackServiceImpl implements CallbackService { private final Map listeners = new ConcurrentHashMap(); diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/ProviderApplication.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/ProviderApplication.java new file mode 100644 index 0000000000..0ed0d93db8 --- /dev/null +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/ProviderApplication.java @@ -0,0 +1,34 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.dubbo.samples.callback.provider; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class ProviderApplication { + + public static void main(String[] args) { + SpringApplication.run(ProviderApplication.class, args); + } + +} diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/resources/application.yml new file mode 100644 index 0000000000..e18c8141df --- /dev/null +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/resources/application.yml @@ -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. +dubbo: + application: + name: callback-provider + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 + protocol: + name: dubbo + port: 20880 + provider: + token: true + callbacks: 1000 diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/resources/log4j.properties new file mode 100644 index 0000000000..723287310b --- /dev/null +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-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-callback/pom.xml b/2-advanced/dubbo-samples-callback/pom.xml index cc956055e0..feba324327 100644 --- a/2-advanced/dubbo-samples-callback/pom.xml +++ b/2-advanced/dubbo-samples-callback/pom.xml @@ -18,30 +18,44 @@ - org.apache.dubbo - 1.0-SNAPSHOT + + org.apache + apache + 23 + + 4.0.0 + org.apache.dubbo dubbo-samples-callback + 1.0-SNAPSHOT + pom + Dubbo Samples Callback Dubbo Samples Callback - 1.8 - 1.8 - 3.1.6 + 3.2.0-beta.4 4.13.1 - 4.3.29.RELEASE - 3.7.0 + 2.7.8 + 1.8 + 1.8 + + dubbo-samples-callback-consumer + dubbo-samples-callback-interface + dubbo-samples-callback-provider + + + - org.springframework - spring-framework-bom - ${spring.version} + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} pom import @@ -58,33 +72,23 @@ ${dubbo.version} pom + + junit + junit + ${junit.version} + test + - - org.apache.dubbo - dubbo - - - - org.apache.dubbo - dubbo-dependencies-zookeeper - pom - junit junit - ${junit.version} test - - org.springframework - spring-test - test - @@ -105,16 +109,14 @@ - - - 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} + + + diff --git a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/EmbeddedZooKeeper.java deleted file mode 100644 index 74ef277fa9..0000000000 --- a/2-advanced/dubbo-samples-callback/src/main/java/org/apache/dubbo/samples/callback/EmbeddedZooKeeper.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * 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.callback; - -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 diff --git a/2-advanced/dubbo-samples-callback/src/main/resources/spring/callback-consumer.xml b/2-advanced/dubbo-samples-callback/src/main/resources/spring/callback-consumer.xml deleted file mode 100644 index ce74d30b7f..0000000000 --- a/2-advanced/dubbo-samples-callback/src/main/resources/spring/callback-consumer.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - diff --git a/2-advanced/dubbo-samples-callback/src/main/resources/spring/callback-provider.xml b/2-advanced/dubbo-samples-callback/src/main/resources/spring/callback-provider.xml deleted file mode 100644 index 299e4e0778..0000000000 --- a/2-advanced/dubbo-samples-callback/src/main/resources/spring/callback-provider.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - From 6a22a53f89c4c0fa927adc1738e7c3ad5039596b Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Wed, 1 Mar 2023 11:07:07 +0800 Subject: [PATCH 02/14] springboot style --- .../samples/callback/CallbackServiceIT.java | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 2-advanced/dubbo-samples-callback/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java diff --git a/2-advanced/dubbo-samples-callback/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java b/2-advanced/dubbo-samples-callback/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java deleted file mode 100644 index 4051439c0a..0000000000 --- a/2-advanced/dubbo-samples-callback/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java +++ /dev/null @@ -1,55 +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.callback; - -import org.apache.dubbo.samples.callback.api.CallbackService; - -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; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "classpath*:spring/callback-consumer.xml") -public class CallbackServiceIT { - @Autowired - @Qualifier("callbackService") - private CallbackService service; - - @Test - public void test() throws InterruptedException { - CountDownLatch latch = new CountDownLatch(1); - List results = new ArrayList<>(); - service.addListener("foo.bar", msg -> { - results.add(msg); - latch.countDown(); - }); - - latch.await(5000, TimeUnit.MILLISECONDS); - Assert.assertFalse(results.isEmpty()); - Assert.assertTrue(results.get(0).startsWith("Changed:")); - } -} From 3cd9a6d84ddff11c87608b5dabdffbebd12525fe Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Fri, 3 Mar 2023 10:00:16 +0800 Subject: [PATCH 03/14] fix: fix CallbackServiceIT error --- .../case-configuration.yml | 28 ++++++++++----- .../dubbo-samples-callback-consumer/pom.xml | 5 ++- .../samples/callback/CallbackServiceIT.java | 36 +++++++++++++++++++ 3 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java diff --git a/2-advanced/dubbo-samples-callback/case-configuration.yml b/2-advanced/dubbo-samples-callback/case-configuration.yml index 073f207937..f98cda163e 100644 --- a/2-advanced/dubbo-samples-callback/case-configuration.yml +++ b/2-advanced/dubbo-samples-callback/case-configuration.yml @@ -14,11 +14,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -from: app-builtin-zookeeper.yml - -props: - project_name: dubbo-samples-callback - main_class: org.apache.dubbo.samples.callback.CallbackProvider - zookeeper_port: 2181 - dubbo_port: 20880 - +service: + callback-provider: + type: app + basedir: dubbo-samples-callback-provider + mainClass: org.apache.dubbo.samples.callback.provider.ProviderApplication + callback-consumer: + type: test + basedir: dubbo-samples-callback-consumer + tests: + - "**/*IT.class" + systemProps: + - zookeeper.address=callback-provider + - zookeeper.port=2181 + - dubbo.address=callback-provider + - dubbo.port=20880 + waitPortsBeforeRun: + - callback-provider:2181 + - callback-provider:20880 + depends_on: + - callback-provider diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/pom.xml b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/pom.xml index a2ffa4c636..b80ca3f68e 100644 --- a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/pom.xml +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/pom.xml @@ -23,7 +23,6 @@ ../pom.xml 4.0.0 - dubbo-samples-callback-consumer @@ -55,6 +54,10 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-starter-test + diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java new file mode 100644 index 0000000000..efc5cfab1a --- /dev/null +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java @@ -0,0 +1,36 @@ +package org.apache.dubbo.samples.callback; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.samples.callback.api.CallbackService; +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; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +@SpringBootTest() +@RunWith(SpringRunner.class) +public class CallbackServiceIT { + @DubboReference + private CallbackService service; + + @Test + public void test() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + List results = new ArrayList<>(); + service.addListener("foo.bar", msg -> { + results.add(msg); + latch.countDown(); + }); + + latch.await(5000, TimeUnit.MILLISECONDS); + Assert.assertFalse(results.isEmpty()); + Assert.assertTrue(results.get(0).startsWith("Changed:")); + } + +} From 40c114710ae44a13402aabeecc890ddf224c9569 Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Fri, 3 Mar 2023 10:01:11 +0800 Subject: [PATCH 04/14] fix: add license head --- .../samples/callback/CallbackServiceIT.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java index efc5cfab1a..45c240d3d9 100644 --- a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.dubbo.samples.callback; import org.apache.dubbo.config.annotation.DubboReference; From fdf525cc651300d4b6f9401dd9c22a6484c8c97a Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Fri, 3 Mar 2023 10:15:24 +0800 Subject: [PATCH 05/14] fix: fix CallbackServiceIT error --- .../org/apache/dubbo/samples/callback/CallbackServiceIT.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java index 45c240d3d9..b2be668bac 100644 --- a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-consumer/src/test/java/org/apache/dubbo/samples/callback/CallbackServiceIT.java @@ -18,6 +18,7 @@ import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.samples.callback.api.CallbackService; +import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,7 +30,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -@SpringBootTest() +@SpringBootTest(classes = {DubboAutoConfiguration.class}) @RunWith(SpringRunner.class) public class CallbackServiceIT { @DubboReference From af2b872dc12fb8bb25b8b62aca597b3f3c9276ef Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Sat, 4 Mar 2023 16:19:45 +0800 Subject: [PATCH 06/14] fix: fix case-configuration.yml error --- 2-advanced/dubbo-samples-callback/case-configuration.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/2-advanced/dubbo-samples-callback/case-configuration.yml b/2-advanced/dubbo-samples-callback/case-configuration.yml index f98cda163e..25c9c42420 100644 --- a/2-advanced/dubbo-samples-callback/case-configuration.yml +++ b/2-advanced/dubbo-samples-callback/case-configuration.yml @@ -14,11 +14,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -service: +services: + zookeeper: + image: zookeeper:latest + callback-provider: type: app basedir: dubbo-samples-callback-provider mainClass: org.apache.dubbo.samples.callback.provider.ProviderApplication + callback-consumer: type: test basedir: dubbo-samples-callback-consumer From 25a2240f2777588f266f0e0a1b542eeb9562b575 Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Sat, 4 Mar 2023 17:20:04 +0800 Subject: [PATCH 07/14] fix: fix integration test --- .../callback/provider/EmbeddedZooKeeper.java | 255 ++++++++++++++++++ .../provider/ProviderApplication.java | 1 + 2 files changed, 256 insertions(+) create mode 100644 2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/EmbeddedZooKeeper.java diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/EmbeddedZooKeeper.java new file mode 100644 index 0000000000..f443c8f6a8 --- /dev/null +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/EmbeddedZooKeeper.java @@ -0,0 +1,255 @@ +/* + * 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.callback.provider; + +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 diff --git a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/ProviderApplication.java b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/ProviderApplication.java index 0ed0d93db8..9bbc0c3770 100644 --- a/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/ProviderApplication.java +++ b/2-advanced/dubbo-samples-callback/dubbo-samples-callback-provider/src/main/java/org/apache/dubbo/samples/callback/provider/ProviderApplication.java @@ -28,6 +28,7 @@ public class ProviderApplication { public static void main(String[] args) { + new EmbeddedZooKeeper(2181,false).start(); SpringApplication.run(ProviderApplication.class, args); } From 9f9e0e0aa1bd089dd8d6a2a750664e5637428e93 Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Sat, 4 Mar 2023 20:44:30 +0800 Subject: [PATCH 08/14] fix: modify case-configuration.yml and case-versions.conf --- .../case-configuration.yml | 52 +++++++++++-------- .../dubbo-samples-callback/case-versions.conf | 3 +- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/2-advanced/dubbo-samples-callback/case-configuration.yml b/2-advanced/dubbo-samples-callback/case-configuration.yml index 25c9c42420..caf363de44 100644 --- a/2-advanced/dubbo-samples-callback/case-configuration.yml +++ b/2-advanced/dubbo-samples-callback/case-configuration.yml @@ -14,27 +14,35 @@ # See the License for the specific language governing permissions and # limitations under the License. -services: - zookeeper: - image: zookeeper:latest +#services: +# zookeeper: +# image: zookeeper:latest +# +# callback-provider: +# type: app +# basedir: dubbo-samples-callback-provider +# mainClass: org.apache.dubbo.samples.callback.provider.ProviderApplication +# +# callback-consumer: +# type: test +# basedir: dubbo-samples-callback-consumer +# tests: +# - "**/*IT.class" +# systemProps: +# - zookeeper.address=callback-provider +# - zookeeper.port=2181 +# - dubbo.address=callback-provider +# - dubbo.port=20880 +# waitPortsBeforeRun: +# - callback-provider:2181 +# - callback-provider:20880 +# depends_on: +# - callback-provider - callback-provider: - type: app - basedir: dubbo-samples-callback-provider - mainClass: org.apache.dubbo.samples.callback.provider.ProviderApplication +from: app-builtin-zookeeper.yml - callback-consumer: - type: test - basedir: dubbo-samples-callback-consumer - tests: - - "**/*IT.class" - systemProps: - - zookeeper.address=callback-provider - - zookeeper.port=2181 - - dubbo.address=callback-provider - - dubbo.port=20880 - waitPortsBeforeRun: - - callback-provider:2181 - - callback-provider:20880 - depends_on: - - callback-provider +props: + project_name: dubbo-samples-callback + main_class: org.apache.dubbo.samples.callback.provider.ProviderApplication + zookeeper_port: 2181 + dubbo_port: 20880 diff --git a/2-advanced/dubbo-samples-callback/case-versions.conf b/2-advanced/dubbo-samples-callback/case-versions.conf index 20c45c863f..eb74c1dbf9 100644 --- a/2-advanced/dubbo-samples-callback/case-versions.conf +++ b/2-advanced/dubbo-samples-callback/case-versions.conf @@ -21,5 +21,6 @@ # Spring app dubbo.version=2.7*, 3.* -spring.version=4.*, 5.* +# spring.version=4.*, 5.* +spring-boot.version=2.* java.version= [<= 11] From 8fd781e10a9afffe4529db9fa02edf85b3404a2c Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Sat, 4 Mar 2023 21:38:17 +0800 Subject: [PATCH 09/14] fix: use zookeeper:latest image --- .../case-configuration.yml | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/2-advanced/dubbo-samples-callback/case-configuration.yml b/2-advanced/dubbo-samples-callback/case-configuration.yml index caf363de44..7b15531f9c 100644 --- a/2-advanced/dubbo-samples-callback/case-configuration.yml +++ b/2-advanced/dubbo-samples-callback/case-configuration.yml @@ -14,35 +14,35 @@ # See the License for the specific language governing permissions and # limitations under the License. -#services: -# zookeeper: -# image: zookeeper:latest -# -# callback-provider: -# type: app -# basedir: dubbo-samples-callback-provider -# mainClass: org.apache.dubbo.samples.callback.provider.ProviderApplication -# -# callback-consumer: -# type: test -# basedir: dubbo-samples-callback-consumer -# tests: -# - "**/*IT.class" -# systemProps: -# - zookeeper.address=callback-provider -# - zookeeper.port=2181 -# - dubbo.address=callback-provider -# - dubbo.port=20880 -# waitPortsBeforeRun: -# - callback-provider:2181 -# - callback-provider:20880 -# depends_on: -# - callback-provider +services: + zookeeper: + image: zookeeper:latest -from: app-builtin-zookeeper.yml + callback-provider: + type: app + basedir: dubbo-samples-callback-provider + mainClass: org.apache.dubbo.samples.callback.provider.ProviderApplication -props: - project_name: dubbo-samples-callback - main_class: org.apache.dubbo.samples.callback.provider.ProviderApplication - zookeeper_port: 2181 - dubbo_port: 20880 + callback-consumer: + type: test + basedir: dubbo-samples-callback-consumer + tests: + - "**/*IT.class" + systemProps: + - zookeeper.address=callback-provider + - zookeeper.port=2181 + - dubbo.address=callback-provider + - dubbo.port=20880 + waitPortsBeforeRun: + - callback-provider:2181 + - callback-provider:20880 + depends_on: + - callback-provider + +#from: app-builtin-zookeeper.yml +# +#props: +# project_name: dubbo-samples-callback +# main_class: org.apache.dubbo.samples.callback.provider.ProviderApplication +# zookeeper_port: 2181 +# dubbo_port: 20880 From 7ada79623bb45fc5028c734ef91b9c0052fa3435 Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Sat, 4 Mar 2023 23:27:53 +0800 Subject: [PATCH 10/14] fix: remove comments --- 2-advanced/dubbo-samples-callback/case-configuration.yml | 8 -------- 2-advanced/dubbo-samples-callback/case-versions.conf | 1 - 2 files changed, 9 deletions(-) diff --git a/2-advanced/dubbo-samples-callback/case-configuration.yml b/2-advanced/dubbo-samples-callback/case-configuration.yml index 7b15531f9c..25c9c42420 100644 --- a/2-advanced/dubbo-samples-callback/case-configuration.yml +++ b/2-advanced/dubbo-samples-callback/case-configuration.yml @@ -38,11 +38,3 @@ services: - callback-provider:20880 depends_on: - callback-provider - -#from: app-builtin-zookeeper.yml -# -#props: -# project_name: dubbo-samples-callback -# main_class: org.apache.dubbo.samples.callback.provider.ProviderApplication -# zookeeper_port: 2181 -# dubbo_port: 20880 diff --git a/2-advanced/dubbo-samples-callback/case-versions.conf b/2-advanced/dubbo-samples-callback/case-versions.conf index eb74c1dbf9..816839de19 100644 --- a/2-advanced/dubbo-samples-callback/case-versions.conf +++ b/2-advanced/dubbo-samples-callback/case-versions.conf @@ -21,6 +21,5 @@ # Spring app dubbo.version=2.7*, 3.* -# spring.version=4.*, 5.* spring-boot.version=2.* java.version= [<= 11] From e0223b28592afa5bf4e5bdc4003b00be18eba6e6 Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Tue, 7 Mar 2023 10:36:21 +0800 Subject: [PATCH 11/14] refactor: dubbo-samples-environment-keys --- .../case-configuration.yml | 29 +++++++++---- .../case-versions.conf | 2 +- .../environment/keys/consumer/Task.java | 33 +++++++++++++++ .../src/main/resources/log4j.properties | 0 .../pom.xml | 29 +++++++++++++ .../environment/keys}/api/DemoService.java | 5 +-- .../keys/provider/DemoServiceImpl.java} | 37 ++++++++--------- .../keys/provider}/EmbeddedZooKeeper.java | 2 +- .../src/main/resources/log4j.properties | 26 ++++++++++++ .../dubbo-samples-environment-keys/pom.xml | 41 +++++++++++++------ .../dubbo/samples/basic/BasicConsumer.java | 35 ---------------- .../dubbo/samples/basic/BasicProvider.java | 41 ------------------- .../samples/basic/impl/DemoServiceImpl.java | 37 ----------------- .../resources/spring/dubbo-demo-consumer.xml | 36 ---------------- .../resources/spring/dubbo-demo-provider.xml | 38 ----------------- 15 files changed, 158 insertions(+), 233 deletions(-) create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/java/org/apache/dubbo/samples/environment/keys/consumer/Task.java rename 2-advanced/dubbo-samples-environment-keys/{ => dubbo-samples-environment-keys-consumer}/src/main/resources/log4j.properties (100%) create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-interface/pom.xml rename 2-advanced/dubbo-samples-environment-keys/{src/main/java/org/apache/dubbo/samples/basic => dubbo-samples-environment-keys-interface/src/main/java/org/dubbo/samples/environment/keys}/api/DemoService.java (94%) rename 2-advanced/dubbo-samples-environment-keys/{src/test/java/org/apache/dubbo/samples/basic/DemoServiceIT.java => dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/DemoServiceImpl.java} (50%) rename 2-advanced/dubbo-samples-environment-keys/{src/main/java/org/apache/dubbo/samples/basic => dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider}/EmbeddedZooKeeper.java (99%) create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/resources/log4j.properties delete mode 100644 2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicConsumer.java delete mode 100644 2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicProvider.java delete mode 100644 2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java delete mode 100644 2-advanced/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-consumer.xml delete mode 100644 2-advanced/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-provider.xml diff --git a/2-advanced/dubbo-samples-environment-keys/case-configuration.yml b/2-advanced/dubbo-samples-environment-keys/case-configuration.yml index 3711aeee9b..4ef4edf456 100644 --- a/2-advanced/dubbo-samples-environment-keys/case-configuration.yml +++ b/2-advanced/dubbo-samples-environment-keys/case-configuration.yml @@ -14,11 +14,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -from: app-builtin-zookeeper.yml - -props: - project_name: dubbo-samples-environment-keys - main_class: org.apache.dubbo.samples.basic.BasicProvider - zookeeper_port: 2181 - dubbo_port: 20880 +services: + zookeeper: + image: zookeeper:latest + environment-keys-provider: + type: app + basedir: dubbo-samples-environment-keys-provider + mainClass: org.apache.dubbo.samples.environment.keys.provider.EnvironmentKeysProviderApplication + environment-keys-consumer: + type: test + basedir: dubbo-samples-environment-keys-consumer + tests: + - "**/*IT.class" + systemProps: + - zookeeper.address=environment-keys-provider + - zookeeper.port=2181 + - dubbo.address=environment-keys-provider + - dubbo.port=20880 + waitPortsBeforeRun: + - environment-keys-provider:2181 + - environment-keys-provider:20880 + depends_on: + - environment-keys-provider diff --git a/2-advanced/dubbo-samples-environment-keys/case-versions.conf b/2-advanced/dubbo-samples-environment-keys/case-versions.conf index 20c45c863f..816839de19 100644 --- a/2-advanced/dubbo-samples-environment-keys/case-versions.conf +++ b/2-advanced/dubbo-samples-environment-keys/case-versions.conf @@ -21,5 +21,5 @@ # Spring app dubbo.version=2.7*, 3.* -spring.version=4.*, 5.* +spring-boot.version=2.* java.version= [<= 11] diff --git a/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/java/org/apache/dubbo/samples/environment/keys/consumer/Task.java b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/java/org/apache/dubbo/samples/environment/keys/consumer/Task.java new file mode 100644 index 0000000000..26568c1c03 --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/java/org/apache/dubbo/samples/environment/keys/consumer/Task.java @@ -0,0 +1,33 @@ +/* + * 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.environment.keys.consumer; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.dubbo.samples.environment.keys.api.DemoService; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +public class Task implements CommandLineRunner { + @DubboReference + private DemoService demoService; + @Override + public void run(String... args) throws Exception { + String hello = demoService.sayHello("world"); + System.out.println(hello); + } +} diff --git a/2-advanced/dubbo-samples-environment-keys/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/resources/log4j.properties similarity index 100% rename from 2-advanced/dubbo-samples-environment-keys/src/main/resources/log4j.properties rename to 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/resources/log4j.properties diff --git a/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-interface/pom.xml b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-interface/pom.xml new file mode 100644 index 0000000000..5b10d8d724 --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-interface/pom.xml @@ -0,0 +1,29 @@ + + + + dubbo-samples-environment-keys + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-samples-environment-keys-interface + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/api/DemoService.java b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-interface/src/main/java/org/dubbo/samples/environment/keys/api/DemoService.java similarity index 94% rename from 2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/api/DemoService.java rename to 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-interface/src/main/java/org/dubbo/samples/environment/keys/api/DemoService.java index f83ffafb08..7bfc1c94b5 100644 --- a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/api/DemoService.java +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-interface/src/main/java/org/dubbo/samples/environment/keys/api/DemoService.java @@ -16,11 +16,8 @@ * limitations under the License. * */ - -package org.apache.dubbo.samples.basic.api; +package org.dubbo.samples.environment.keys.api; public interface DemoService { - String sayHello(String name); - } diff --git a/2-advanced/dubbo-samples-environment-keys/src/test/java/org/apache/dubbo/samples/basic/DemoServiceIT.java b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/DemoServiceImpl.java similarity index 50% rename from 2-advanced/dubbo-samples-environment-keys/src/test/java/org/apache/dubbo/samples/basic/DemoServiceIT.java rename to 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/DemoServiceImpl.java index 430eda6ae6..4619508136 100644 --- a/2-advanced/dubbo-samples-environment-keys/src/test/java/org/apache/dubbo/samples/basic/DemoServiceIT.java +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/DemoServiceImpl.java @@ -14,29 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package org.apache.dubbo.samples.environment.keys.provider; -package org.apache.dubbo.samples.basic; +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.rpc.RpcContext; +import org.dubbo.samples.environment.keys.api.DemoService; -import org.apache.dubbo.samples.basic.api.DemoService; +import java.text.SimpleDateFormat; +import java.util.Date; -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/dubbo-demo-consumer.xml") -public class DemoServiceIT { - - @Autowired - @Qualifier("demoService") - private DemoService service; +/** + * @Descrpition + * @Date 2023/3/7 + */ +@DubboService +public class DemoServiceImpl implements DemoService { + @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(); - @Test - public void testGreeting() throws Exception { - Assert.assertTrue(service.sayHello("dubbo").startsWith("Hello dubbo")); } } diff --git a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/EmbeddedZooKeeper.java similarity index 99% rename from 2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/EmbeddedZooKeeper.java rename to 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/EmbeddedZooKeeper.java index 969c9b8e27..38f709f1ba 100644 --- a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/EmbeddedZooKeeper.java +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/EmbeddedZooKeeper.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.samples.basic; +package org.apache.dubbo.samples.environment.keys.provider; import org.apache.zookeeper.server.ServerConfig; import org.apache.zookeeper.server.ZooKeeperServerMain; diff --git a/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/resources/log4j.properties new file mode 100644 index 0000000000..d6ecd5ce34 --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-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-environment-keys/pom.xml b/2-advanced/dubbo-samples-environment-keys/pom.xml index 91aff74e12..65b5207bb4 100644 --- a/2-advanced/dubbo-samples-environment-keys/pom.xml +++ b/2-advanced/dubbo-samples-environment-keys/pom.xml @@ -18,29 +18,42 @@ - org.apache.dubbo - 1.0-SNAPSHOT - + + org.apache + apache + 23 + + 4.0.0 + org.apache.dubbo + 1.0-SNAPSHOT dubbo-samples-environment-keys Dubbo Samples Environment Keys Dubbo Samples Environment Keys + pom 1.8 1.8 3.1.6 4.13.1 - 4.3.29.RELEASE + 2.7.8 + + dubbo-samples-environment-keys-interface + dubbo-samples-environment-keys-provider + dubbo-samples-environment-keys-consumer + + + - org.springframework - spring-framework-bom - ${spring.version} + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} pom import @@ -82,12 +95,6 @@ junit test - - - org.springframework - spring-test - test - @@ -118,9 +125,17 @@ ${target.level} + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + apache.snapshots.https diff --git a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicConsumer.java b/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicConsumer.java deleted file mode 100644 index 4532160924..0000000000 --- a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicConsumer.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.basic; - -import org.apache.dubbo.samples.basic.api.DemoService; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class BasicConsumer { - - public static void main(String[] args) { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml"); - context.start(); - DemoService demoService = (DemoService) context.getBean("demoService"); - String hello = demoService.sayHello("world"); - System.out.println(hello); - } -} diff --git a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicProvider.java b/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicProvider.java deleted file mode 100644 index 7e64a53241..0000000000 --- a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicProvider.java +++ /dev/null @@ -1,41 +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.basic; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class BasicProvider { - - public static void main(String[] args) throws Exception { - new EmbeddedZooKeeper(2181, false).start(); - // wait for embedded zookeeper start completely. - Thread.sleep(1000); - - System.setProperty("dubbo.labels", "dubbo.key1=value1; dubbo.key2=value2"); - System.setProperty("dubbo.env.keys", "DUBBO_KEY1, DUBBO_KEY2"); - - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml"); - context.start(); - - System.out.println("dubbo service started"); - System.in.read(); - } - -} diff --git a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java b/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java deleted file mode 100644 index 242fcc31dd..0000000000 --- a/2-advanced/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java +++ /dev/null @@ -1,37 +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.basic.impl; - -import org.apache.dubbo.rpc.RpcContext; -import org.apache.dubbo.samples.basic.api.DemoService; - -import java.text.SimpleDateFormat; -import java.util.Date; - -public class DemoServiceImpl implements DemoService { - - @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-environment-keys/src/main/resources/spring/dubbo-demo-consumer.xml b/2-advanced/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-consumer.xml deleted file mode 100644 index 651b7f7840..0000000000 --- a/2-advanced/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-consumer.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/2-advanced/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-provider.xml b/2-advanced/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-provider.xml deleted file mode 100644 index 438f69ac1e..0000000000 --- a/2-advanced/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-provider.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - From e66508391cba95733f8aa851323acbfb9290365e Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Tue, 7 Mar 2023 14:01:35 +0800 Subject: [PATCH 12/14] fix: add maven configuration --- .../pom.xml | 78 +++++++++++++++++++ .../EnvironmentKeysConsumerApplication.java | 31 ++++++++ .../src/main/resources/application.yml | 25 ++++++ .../keys/consumer/DemoServiceIT.java | 39 ++++++++++ .../pom.xml | 72 +++++++++++++++++ .../EnvironmentKeysProviderApplication.java | 35 +++++++++ .../src/main/resources/application.yml | 26 +++++++ 7 files changed, 306 insertions(+) create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/pom.xml create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/java/org/apache/dubbo/samples/environment/keys/consumer/EnvironmentKeysConsumerApplication.java create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/test/java/org/apache/dubbo/samples/environment/keys/consumer/DemoServiceIT.java create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/pom.xml create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/EnvironmentKeysProviderApplication.java create mode 100644 2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/resources/application.yml diff --git a/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/pom.xml b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/pom.xml new file mode 100644 index 0000000000..98c325196a --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + dubbo-samples-environment-keys + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + + dubbo-samples-environment-keys-consumer + + + + org.apache.dubbo + dubbo-samples-environment-keys-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-environment-keys/dubbo-samples-environment-keys-consumer/src/main/java/org/apache/dubbo/samples/environment/keys/consumer/EnvironmentKeysConsumerApplication.java b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/java/org/apache/dubbo/samples/environment/keys/consumer/EnvironmentKeysConsumerApplication.java new file mode 100644 index 0000000000..ed560c926a --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/java/org/apache/dubbo/samples/environment/keys/consumer/EnvironmentKeysConsumerApplication.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.samples.environment.keys.consumer; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class EnvironmentKeysConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(EnvironmentKeysConsumerApplication.class, args); + } + +} diff --git a/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/resources/application.yml new file mode 100644 index 0000000000..575b238595 --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/main/resources/application.yml @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +dubbo: + application: + name: demo-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-environment-keys/dubbo-samples-environment-keys-consumer/src/test/java/org/apache/dubbo/samples/environment/keys/consumer/DemoServiceIT.java b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/test/java/org/apache/dubbo/samples/environment/keys/consumer/DemoServiceIT.java new file mode 100644 index 0000000000..8e326c0eec --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-consumer/src/test/java/org/apache/dubbo/samples/environment/keys/consumer/DemoServiceIT.java @@ -0,0 +1,39 @@ +/* + * 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.environment.keys.consumer; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration; +import org.dubbo.samples.environment.keys.api.DemoService; +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(classes = {DubboAutoConfiguration.class}) +@RunWith(SpringRunner.class) +public class DemoServiceIT { + + @DubboReference + private DemoService demoService; + @Test + public void test() { + Assert.assertTrue(demoService.sayHello("dubbo").startsWith("Hello dubbo")); + } + +} diff --git a/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/pom.xml b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/pom.xml new file mode 100644 index 0000000000..88e7066c19 --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + dubbo-samples-environment-keys + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + dubbo-samples-environment-keys-provider + + + org.apache.dubbo + dubbo-samples-environment-keys-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-maven-plugin + + + + repackage + + + + + + + + diff --git a/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/EnvironmentKeysProviderApplication.java b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/EnvironmentKeysProviderApplication.java new file mode 100644 index 0000000000..132352d3d8 --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/java/org/apache/dubbo/samples/environment/keys/provider/EnvironmentKeysProviderApplication.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.environment.keys.provider; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class EnvironmentKeysProviderApplication { + + + public static void main(String[] args) { + new EmbeddedZooKeeper(2181,false).start(); + System.setProperty("dubbo.labels", "dubbo.key1=value1; dubbo.key2=value2"); + System.setProperty("dubbo.env.keys", "DUBBO_KEY1, DUBBO_KEY2"); + SpringApplication.run(EnvironmentKeysProviderApplication.class, args); + } + +} diff --git a/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/resources/application.yml new file mode 100644 index 0000000000..a68cb41e65 --- /dev/null +++ b/2-advanced/dubbo-samples-environment-keys/dubbo-samples-environment-keys-provider/src/main/resources/application.yml @@ -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. +dubbo: + application: + name: demo-provider + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 +# protocol: +# name: dubbo +# port: 20880 +# host: 192.168.1.104 + provider: + token: true \ No newline at end of file From 268aa6bdbeb0ae177a957dc9534bca20c59100e9 Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Tue, 7 Mar 2023 14:40:54 +0800 Subject: [PATCH 13/14] fix: modify dubbo version --- 2-advanced/dubbo-samples-environment-keys/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-advanced/dubbo-samples-environment-keys/pom.xml b/2-advanced/dubbo-samples-environment-keys/pom.xml index 65b5207bb4..1eb3fadc81 100644 --- a/2-advanced/dubbo-samples-environment-keys/pom.xml +++ b/2-advanced/dubbo-samples-environment-keys/pom.xml @@ -36,7 +36,7 @@ 1.8 1.8 - 3.1.6 + 3.2.0-beta.6-SNAPSHOT 4.13.1 2.7.8 From 1e57bc64a8cff3d82bd47c225f0bb41007bff1ae Mon Sep 17 00:00:00 2001 From: jianbo <1784749609@qq.com> Date: Tue, 7 Mar 2023 15:24:06 +0800 Subject: [PATCH 14/14] fix: fix case-configuration.yml --- .../case-configuration.yml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/2-advanced/dubbo-samples-environment-keys/case-configuration.yml b/2-advanced/dubbo-samples-environment-keys/case-configuration.yml index 4ef4edf456..cb355dc19e 100644 --- a/2-advanced/dubbo-samples-environment-keys/case-configuration.yml +++ b/2-advanced/dubbo-samples-environment-keys/case-configuration.yml @@ -26,14 +26,14 @@ services: basedir: dubbo-samples-environment-keys-consumer tests: - "**/*IT.class" - systemProps: - - zookeeper.address=environment-keys-provider - - zookeeper.port=2181 - - dubbo.address=environment-keys-provider - - dubbo.port=20880 - waitPortsBeforeRun: - - environment-keys-provider:2181 - - environment-keys-provider:20880 - depends_on: - - environment-keys-provider + systemProps: + - zookeeper.address=environment-keys-provider + - zookeeper.port=2181 + - dubbo.address=environment-keys-provider + - dubbo.port=20880 + waitPortsBeforeRun: + - environment-keys-provider:2181 + - environment-keys-provider:20880 + depends_on: + - environment-keys-provider