diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml
index e3a0ddf195..52e00981c1 100644
--- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml
+++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml
@@ -20,6 +20,7 @@
dubbo:
application:
name: local-consumer
+ logger: slf4j
protocol:
name: dubbo
port: -1
diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java
new file mode 100644
index 0000000000..b1e8539d7a
--- /dev/null
+++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/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.local;
+
+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-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java
index e1fae07b32..c5a2d6a61b 100644
--- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java
+++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java
@@ -23,6 +23,7 @@
import org.apache.dubbo.samples.local.api.LocalService;
import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration;
import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
@@ -34,11 +35,16 @@ public class LocalServiceIT {
@DubboReference
private LocalService localService;
+ @BeforeClass
+ public static void setUp() throws Exception {
+ new EmbeddedZooKeeper(2181, false).start();
+ }
+
@Test
public void test() throws Exception {
String result = localService.sayHello("world");
- Assert.assertEquals(result, "Hello world, response from provider: 10.193.180.32:20880");
+ Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0");
result = localService.sayHelloAsync("world");
- Assert.assertEquals(result, "Hello world, response from provider: 10.193.180.32:20880");
+ Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0");
}
}
diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml
index 24655c0133..e09a81a319 100644
--- a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml
+++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml
@@ -28,10 +28,6 @@
dubbo-samples-local-provider
-
- 3.8.0
-
-
@@ -61,71 +57,8 @@
org.springframework.boot
spring-boot-starter
-
-
- org.apache.zookeeper
- zookeeper
- ${zookeeper.version}
-
-
- netty-handler
- io.netty
-
-
- netty-transport-native-epoll
- io.netty
-
-
-
-
- commons-cli
- commons-cli
- 1.4
-
-
- org.eclipse.jetty
- jetty-server
-
-
- org.eclipse.jetty
- jetty-servlet
-
-
- org.eclipse.jetty
- jetty-client
-
-
- jline
- jline
- 2.14.6
-
-
- io.dropwizard.metrics
- metrics-core
-
-
- org.xerial.snappy
- snappy-java
-
-
-
-
- javax.annotation
-
- [1.11,)
-
-
-
- javax.annotation
- javax.annotation-api
- 1.3.2
-
-
-
-
-
diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml
index 04bc500c29..37e8f056d5 100644
--- a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml
+++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml
@@ -19,6 +19,7 @@
dubbo:
application:
name: local-provider
+ logger: slf4j
protocol:
name: dubbo
port: 20880
diff --git a/2-advanced/dubbo-samples-local/pom.xml b/2-advanced/dubbo-samples-local/pom.xml
index 5c7dfe4aad..a682fe0696 100644
--- a/2-advanced/dubbo-samples-local/pom.xml
+++ b/2-advanced/dubbo-samples-local/pom.xml
@@ -18,6 +18,13 @@
+
+ org.apache
+ apache
+ 23
+
+
+
dubbo-samples-local-provider
dubbo-samples-local-consumer
@@ -37,7 +44,6 @@
3.2.0-beta.4
2.7.8
- 4.13.1
1.8
1.8
UTF-8
From b13707af30744c8be189f7630283091005a97860 Mon Sep 17 00:00:00 2001
From: fyf <2569548856@qq.com>
Date: Tue, 7 Mar 2023 11:10:57 +0800
Subject: [PATCH 6/9] add junit version
---
2-advanced/dubbo-samples-local/pom.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/2-advanced/dubbo-samples-local/pom.xml b/2-advanced/dubbo-samples-local/pom.xml
index a682fe0696..3f1226ab9d 100644
--- a/2-advanced/dubbo-samples-local/pom.xml
+++ b/2-advanced/dubbo-samples-local/pom.xml
@@ -44,6 +44,7 @@
3.2.0-beta.4
2.7.8
+ 4.13.1
1.8
1.8
UTF-8
From f04281297912f1ac49a3cbc2b4e1c470498a66f4 Mon Sep 17 00:00:00 2001
From: fyf <2569548856@qq.com>
Date: Tue, 7 Mar 2023 11:54:38 +0800
Subject: [PATCH 7/9] remove embedded-zookeeper module
---
.../dubbo-samples-local-consumer/pom.xml | 6 ------
1 file changed, 6 deletions(-)
diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml
index d561d25a0d..acd99609a4 100644
--- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml
+++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml
@@ -70,12 +70,6 @@
4.13.1
test
-
- org.apache.dubbo
- embedded-zookeeper
- 1.0-SNAPSHOT
- test
-
From b27ca6932311d177239ab7d31146aac3e76d6c41 Mon Sep 17 00:00:00 2001
From: fyf <2569548856@qq.com>
Date: Tue, 7 Mar 2023 17:08:35 +0800
Subject: [PATCH 8/9] add localAddress
---
.../org/apache/dubbo/samples/local/LocalServiceIT.java | 8 ++++++--
nacos-mysql/Dockerfile | 5 +++++
2 files changed, 11 insertions(+), 2 deletions(-)
create mode 100644 nacos-mysql/Dockerfile
diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java
index c5a2d6a61b..9fee0fad74 100644
--- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java
+++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java
@@ -20,6 +20,7 @@
package org.apache.dubbo.samples.local;
import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.samples.local.api.LocalService;
import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration;
import org.junit.Assert;
@@ -29,6 +30,8 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
+import java.net.InetSocketAddress;
+
@SpringBootTest(classes = {DubboAutoConfiguration.class})
@RunWith(SpringRunner.class)
public class LocalServiceIT {
@@ -42,9 +45,10 @@ public static void setUp() throws Exception {
@Test
public void test() throws Exception {
+ InetSocketAddress localAddress = RpcContext.getContext().getLocalAddress();
String result = localService.sayHello("world");
- Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0");
+ Assert.assertEquals(result, "Hello world, response from provider: " + localAddress);
result = localService.sayHelloAsync("world");
- Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0");
+ Assert.assertEquals(result, "Hello world, response from provider: " + localAddress);
}
}
diff --git a/nacos-mysql/Dockerfile b/nacos-mysql/Dockerfile
new file mode 100644
index 0000000000..d520f38a1e
--- /dev/null
+++ b/nacos-mysql/Dockerfile
@@ -0,0 +1,5 @@
+FROM mysql:5.7.40
+ADD https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql /docker-entrypoint-initdb.d/nacos-mysql.sql
+RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/nacos-mysql.sql
+EXPOSE 3306
+CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
\ No newline at end of file
From b45fd1e0d1741cd996fa027dcd378bdc8f991320 Mon Sep 17 00:00:00 2001
From: fyf <2569548856@qq.com>
Date: Tue, 7 Mar 2023 17:27:18 +0800
Subject: [PATCH 9/9] remove useless dir
---
nacos-mysql/Dockerfile | 5 -----
1 file changed, 5 deletions(-)
delete mode 100644 nacos-mysql/Dockerfile
diff --git a/nacos-mysql/Dockerfile b/nacos-mysql/Dockerfile
deleted file mode 100644
index d520f38a1e..0000000000
--- a/nacos-mysql/Dockerfile
+++ /dev/null
@@ -1,5 +0,0 @@
-FROM mysql:5.7.40
-ADD https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql /docker-entrypoint-initdb.d/nacos-mysql.sql
-RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/nacos-mysql.sql
-EXPOSE 3306
-CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
\ No newline at end of file