diff --git a/2-advanced/dubbo-samples-local/case-configuration.yml b/2-advanced/dubbo-samples-local/case-configuration.yml index b23ab56d6c..db73bf9dc9 100644 --- a/2-advanced/dubbo-samples-local/case-configuration.yml +++ b/2-advanced/dubbo-samples-local/case-configuration.yml @@ -17,8 +17,33 @@ # local call through injvm, start test container only services: - dubbo-samples-local-test: + zookeeper: + image: zookeeper:latest + + local-provider: + type: app + basedir: dubbo-samples-local-provider + mainClass: org.apache.dubbo.samples.local.LocalProvider + systemProps: + - zookeeper.address=zookeeper + waitPortsBeforeRun: + - zookeeper:2181 + checkPorts: + - 20880 + checkLog: "Current Spring Boot Application is await" + depends_on: + - zookeeper + + local-consumer: type: test - basedir: . + basedir: dubbo-samples-local-consumer tests: - - "**/*IT.class" \ No newline at end of file + - "**/*IT.class" + systemProps: + - zookeeper.address=zookeeper + waitPortsBeforeRun: + - zookeeper:2181 + - local-provider:20880 + depends_on: + - zookeeper + - local-provider \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/case-versions.conf b/2-advanced/dubbo-samples-local/case-versions.conf index 9a2ae82744..20c45c863f 100644 --- a/2-advanced/dubbo-samples-local/case-versions.conf +++ b/2-advanced/dubbo-samples-local/case-versions.conf @@ -20,6 +20,6 @@ # Supported component versions of the test case # Spring app -dubbo.version=3.* +dubbo.version=2.7*, 3.* spring.version=4.*, 5.* java.version= [<= 11] 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 new file mode 100644 index 0000000000..acd99609a4 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml @@ -0,0 +1,107 @@ + + + + + dubbo-samples-local + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-samples-local-consumer + + + + + org.apache.dubbo + dubbo-samples-local-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-test + test + + + + junit + junit + 4.13.1 + test + + + + + + + javax.annotation + + [1.11,) + + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/LocalDemo.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/LocalConsumer.java similarity index 54% rename from 2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/LocalDemo.java rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/LocalConsumer.java index 94ea847d4c..d4cb42fa50 100644 --- a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/LocalDemo.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/LocalConsumer.java @@ -16,26 +16,16 @@ * limitations under the License. * */ - package org.apache.dubbo.samples.local; -import org.apache.dubbo.samples.local.api.DemoService; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.util.concurrent.CountDownLatch; - -public class LocalDemo { - - public static void main(String[] args) throws InterruptedException { - new EmbeddedZooKeeper(2181, true).start(); - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo.xml"); - context.start(); - System.out.println("dubbo service started"); +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; - DemoService demoService = context.getBean("demoService", DemoService.class); - String hello = demoService.sayHello("world"); - System.out.println(hello); - new CountDownLatch(1).await(); +@SpringBootApplication +@EnableDubbo +public class LocalConsumer { + public static void main(String[] args) { + SpringApplication.run(LocalConsumer.class, args); } } diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/Task.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/Task.java new file mode 100644 index 0000000000..dfe8fcbab6 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/Task.java @@ -0,0 +1,52 @@ +/* + * + * 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.local; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.samples.local.api.LocalService; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import java.util.Date; + +@Component +public class Task implements CommandLineRunner { + + @DubboReference + private LocalService localService; + + @Override + public void run(String... args) throws Exception { + String result = localService.sayHello("world"); + System.out.println("Receive result ======> " + result); + + new Thread(()->{ + while (true) { + try { + Thread.sleep(1000); + System.out.println(new Date() + " Receive result ======> " + localService.sayHello("world")); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + } + }).start(); + } +} 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 new file mode 100644 index 0000000000..52e00981c1 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml @@ -0,0 +1,28 @@ +# +# +# 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: local-consumer + logger: slf4j + 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-local/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/log4j.properties similarity index 100% rename from 2-advanced/dubbo-samples-local/src/main/resources/log4j.properties rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/log4j.properties diff --git a/2-advanced/dubbo-samples-local/src/main/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 similarity index 100% rename from 2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java 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 new file mode 100644 index 0000000000..9fee0fad74 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java @@ -0,0 +1,54 @@ +/* + * + * 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.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; +import org.junit.BeforeClass; +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.net.InetSocketAddress; + +@SpringBootTest(classes = {DubboAutoConfiguration.class}) +@RunWith(SpringRunner.class) +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 { + InetSocketAddress localAddress = RpcContext.getContext().getLocalAddress(); + String result = localService.sayHello("world"); + Assert.assertEquals(result, "Hello world, response from provider: " + localAddress); + result = localService.sayHelloAsync("world"); + Assert.assertEquals(result, "Hello world, response from provider: " + localAddress); + } +} diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml new file mode 100644 index 0000000000..80054da76d --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml @@ -0,0 +1,31 @@ + + + + + dubbo-samples-local + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-samples-local-interface + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/api/DemoService.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/src/main/java/org/apache/dubbo/samples/local/api/LocalService.java similarity index 96% rename from 2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/api/DemoService.java rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-interface/src/main/java/org/apache/dubbo/samples/local/api/LocalService.java index 7492773e04..3d272d4bc4 100644 --- a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/api/DemoService.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/src/main/java/org/apache/dubbo/samples/local/api/LocalService.java @@ -19,7 +19,7 @@ package org.apache.dubbo.samples.local.api; -public interface DemoService { +public interface LocalService { String sayHello(String name); 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 new file mode 100644 index 0000000000..e09a81a319 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml @@ -0,0 +1,77 @@ + + + + + dubbo-samples-local + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + + dubbo-samples-local-provider + + + + + org.apache.dubbo + dubbo-samples-local-interface + ${project.parent.version} + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + + org.apache.dubbo + dubbo-dependencies-zookeeper-curator5 + pom + + + slf4j-reload4j + org.slf4j + + + + + + org.springframework.boot + spring-boot-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/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-provider/src/main/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-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java new file mode 100644 index 0000000000..42c320ecfd --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.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.local; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class LocalProvider { + public static void main(String[] args) { + // Start the registry + new EmbeddedZooKeeper(2181, false).start(); + SpringApplication.run(LocalProvider.class, args); + } +} diff --git a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/impl/DemoServiceImpl.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/impl/LocalServiceImpl.java similarity index 90% rename from 2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/impl/DemoServiceImpl.java rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/impl/LocalServiceImpl.java index da897ca7ab..faea68d968 100644 --- a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/impl/DemoServiceImpl.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/impl/LocalServiceImpl.java @@ -16,19 +16,21 @@ * limitations under the License. * */ - package org.apache.dubbo.samples.local.impl; +import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.rpc.AsyncContext; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcServiceContext; -import org.apache.dubbo.samples.local.api.DemoService; +import org.apache.dubbo.samples.local.api.LocalService; import java.text.SimpleDateFormat; import java.util.Date; -public class DemoServiceImpl implements DemoService { +@DubboService +public class LocalServiceImpl implements LocalService { + @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()); 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 new file mode 100644 index 0000000000..37e8f056d5 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml @@ -0,0 +1,27 @@ +# +# +# 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: local-provider + logger: slf4j + protocol: + name: dubbo + port: 20880 + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/log4j.properties new file mode 100644 index 0000000000..2e299bbb25 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/log4j.properties @@ -0,0 +1,23 @@ +# +# +# 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. +# +# +log4j.rootLogger=info, stdout +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 diff --git a/2-advanced/dubbo-samples-local/pom.xml b/2-advanced/dubbo-samples-local/pom.xml index 4712d95893..3f1226ab9d 100644 --- a/2-advanced/dubbo-samples-local/pom.xml +++ b/2-advanced/dubbo-samples-local/pom.xml @@ -18,33 +18,49 @@ - org.apache.dubbo - 1.0-SNAPSHOT + + org.apache + apache + 23 + + + + + dubbo-samples-local-provider + dubbo-samples-local-consumer + dubbo-samples-local-interface + 4.0.0 + org.apache.dubbo dubbo-samples-local + 1.0-SNAPSHOT + pom + Dubbo Samples Local Dubbo Samples Local - 1.8 - 1.8 - 3.1.6 - 4.3.29.RELEASE + 3.2.0-beta.4 + 2.7.8 4.13.1 - 3.7.0 + 1.8 + 1.8 + UTF-8 + - org.springframework - spring-framework-bom - ${spring.version} + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} pom import + org.apache.dubbo dubbo-bom @@ -52,27 +68,24 @@ pom import + org.apache.dubbo - dubbo-dependencies-zookeeper + dubbo-dependencies-zookeeper-curator5 ${dubbo.version} pom + + + junit + junit + ${junit.version} + test + - - org.apache.dubbo - dubbo - - - - org.apache.dubbo - dubbo-dependencies-zookeeper - pom - - junit junit @@ -87,34 +100,15 @@ - - - - javax.annotation - - [1.11,) - - - - javax.annotation - javax.annotation-api - 1.3.2 - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${source.level} - ${target.level} - - - + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + diff --git a/2-advanced/dubbo-samples-local/src/main/resources/spring/dubbo-demo.xml b/2-advanced/dubbo-samples-local/src/main/resources/spring/dubbo-demo.xml deleted file mode 100644 index 6f33dbf3b5..0000000000 --- a/2-advanced/dubbo-samples-local/src/main/resources/spring/dubbo-demo.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/2-advanced/dubbo-samples-local/src/test/java/org/apache/dubbo/samples/local/DemoServiceIT.java b/2-advanced/dubbo-samples-local/src/test/java/org/apache/dubbo/samples/local/DemoServiceIT.java deleted file mode 100644 index a865062d76..0000000000 --- a/2-advanced/dubbo-samples-local/src/test/java/org/apache/dubbo/samples/local/DemoServiceIT.java +++ /dev/null @@ -1,53 +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.local; - -import org.apache.dubbo.samples.local.api.DemoService; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:/spring/dubbo-demo.xml"}) -public class DemoServiceIT { - @Autowired - private DemoService demoService; - - @BeforeClass - public static void setUp() throws Exception { - new EmbeddedZooKeeper(2181, false).start(); - } - - @Test - public void test() throws Exception { - // see also: org.apache.dubbo.rpc.protocol.injvm.InjvmInvoker.doInvoke - // InjvmInvoker set remote address to 127.0.0.1:0 - String result = demoService.sayHello("world"); - Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0"); - - result = demoService.sayHelloAsync("world"); - Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0"); - - } - -}