You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by li...@apache.org on 2019/03/28 06:45:55 UTC
[incubator-dubbo-samples] branch 3.x updated: Merge pull request
#68, add sample for RSocket.
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-samples.git
The following commit(s) were added to refs/heads/3.x by this push:
new fdaea53 Merge pull request #68, add sample for RSocket.
fdaea53 is described below
commit fdaea535a09557ad8f7df580503ca4e16ca2b1f9
Author: uglycow <xi...@gmail.com>
AuthorDate: Thu Mar 28 14:45:50 2019 +0800
Merge pull request #68, add sample for RSocket.
---
dubbo-samples-rsocket/pom.xml | 330 +++++++++++++++++++++
.../dubbo/samples/basic/EmbeddedZooKeeper.java | 256 ++++++++++++++++
.../dubbo/samples/basic/RsocketConsumer.java | 65 ++++
.../dubbo/samples/basic/RsocketProvider.java | 34 +++
.../dubbo/samples/basic/api/DemoService.java | 39 +++
.../dubbo/samples/basic/impl/DemoServiceImpl.java | 87 ++++++
.../src/main/resources/log4j.properties | 26 ++
.../src/main/resources/spring/rsocket-consumer.xml | 36 +++
.../src/main/resources/spring/rsocket-provider.xml | 42 +++
pom.xml | 1 +
10 files changed, 916 insertions(+)
diff --git a/dubbo-samples-rsocket/pom.xml b/dubbo-samples-rsocket/pom.xml
new file mode 100644
index 0000000..7267f32
--- /dev/null
+++ b/dubbo-samples-rsocket/pom.xml
@@ -0,0 +1,330 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-samples-rsocket</artifactId>
+
+ <properties>
+ <source.level>1.8</source.level>
+ <target.level>1.8</target.level>
+ <spring.version>4.3.16.RELEASE</spring.version>
+ <dubbo.version>3.0.0-SNAPSHOT</dubbo.version>
+ <dubbo.rpc.version>3.0.0-SNAPSHOT</dubbo.rpc.version>
+ <zookeeper.version>3.4.13</zookeeper.version>
+ <curator.version>4.0.1</curator.version>
+ <validation-api.version>1.1.0.Final</validation-api.version>
+ <hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
+ <resteasy.version>3.0.19.Final</resteasy.version>
+ <curator-client.version>4.0.1</curator-client.version>
+ <swagger.version>1.5.19</swagger.version>
+ <tomcat.version>7.0.88</tomcat.version>
+ <servlet.version>3.0.1</servlet.version>
+ <maven_checkstyle_version>3.0.0</maven_checkstyle_version>
+ <apache-rat-plugin.version>0.12</apache-rat-plugin.version>
+ <spring-boot.version>1.5.13.RELEASE</spring-boot.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-framework-bom</artifactId>
+ <version>${spring.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <!-- Import dependency management from Spring Boot -->
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring-boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
+ <version>4.1.16.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ <version>${dubbo.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.thrift</groupId>
+ <artifactId>libthrift</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-rpc-rest</artifactId>
+ <version>${dubbo.rpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ <version>${zookeeper.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-framework</artifactId>
+ <version>${curator.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>${validation-api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>${hibernate-validator.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jackson-provider</artifactId>
+ <version>${resteasy.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-client</artifactId>
+ <version>${curator-client.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${servlet.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-core</artifactId>
+ <version>${tomcat.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-logging-juli</artifactId>
+ <version>${tomcat.version}</version>
+ </dependency>
+ <!-- swagger -->
+ <dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-annotations</artifactId>
+ <version>${swagger.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-jaxrs</artifactId>
+ <version>${swagger.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-framework</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>io.netty</groupId>
+ <artifactId>netty</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-rpc-rsocket</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-core</artifactId>
+ <version>3.2.3.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-zookeeper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </dependency>
+ </dependencies>
+
+
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot.version}</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.7.0</version>
+ <configuration>
+ <source>${source.level}</source>
+ <target>${target.level}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>${apache-rat-plugin.version}</version>
+ <executions>
+ <execution>
+ <id>verify.rat</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <excludes>
+ <exclude>**/*.versionsBackup</exclude>
+ <exclude>**/.idea/</exclude>
+ <exclude>**/*.iml</exclude>
+ <exclude>**/*.txt</exclude>
+ <exclude>**/*.load</exclude>
+ <exclude>**/*.flex</exclude>
+ <exclude>**/*.fc</exclude>
+ <exclude>**/*.javascript</exclude>
+ <exclude>**/*.properties</exclude>
+ <exclude>**/*.thrift</exclude>
+ <exclude>**/*.sh</exclude>
+ <exclude>**/*.bat</exclude>
+ <exclude>**/*.md</exclude>
+ <exclude>.git/</exclude>
+ <exclude>.gitignore</exclude>
+ <!-- ASF jenkins box puts the Maven repo in our root directory. -->
+ <exclude>.repository/</exclude>
+ <exclude>**/.settings/*</exclude>
+ <exclude>**/.classpath</exclude>
+ <exclude>**/.project</exclude>
+ <exclude>**/target/**</exclude>
+ <exclude>**/*.log</exclude>
+ <exclude>CODE_OF_CONDUCT.md</exclude>
+ <exclude>.codecov.yml</exclude>
+ <exclude>.travis.yml</exclude>
+ <exclude>PULL_REQUEST_TEMPLATE.md</exclude>
+ <exclude>CONTRIBUTING.md</exclude>
+ <exclude>README.md</exclude>
+ <exclude>**/codestyle/*</exclude>
+ <exclude>**/resources/META-INF/**</exclude>
+ <exclude>**/webapp/swagger/**</exclude>
+ <exclude>**/org/apache/dubbo/samples/rpc/nativethrift/api/DemoService.java</exclude>
+ </excludes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>checkstyle</id>
+ <activation>
+ <jdk>[1.8,)</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${maven_checkstyle_version}</version>
+ <dependencies>
+ <dependency>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>8.9</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>checkstyle-validation</id>
+ <phase>validate</phase>
+ <configuration>
+ <configLocation>../codestyle/checkstyle.xml</configLocation>
+ <suppressionsLocation>../codestyle/checkstyle-suppressions.xml</suppressionsLocation>
+ <encoding>UTF-8</encoding>
+ <consoleOutput>true</consoleOutput>
+ <failOnViolation>true</failOnViolation>
+ </configuration>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/EmbeddedZooKeeper.java b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..13504d5
--- /dev/null
+++ b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/EmbeddedZooKeeper.java
@@ -0,0 +1,256 @@
+/*
+ * 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.basic;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+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;
+
+/**
+ * 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.
+ * <p>
+ * 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/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/RsocketConsumer.java b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/RsocketConsumer.java
new file mode 100644
index 0000000..a40e3ae
--- /dev/null
+++ b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/RsocketConsumer.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+import java.util.function.Consumer;
+
+public class RsocketConsumer {
+
+ public static void main(String[] args) {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/rsocket-consumer.xml"});
+ context.start();
+ DemoService demoService = (DemoService) context.getBean("demoService"); // get remote service proxy
+
+ while (true) {
+ try {
+ Thread.sleep(1000);
+ String hello = demoService.sayHello("world"); // call remote method
+ System.out.println(hello); // get result
+
+
+ Mono<String> monoResult = demoService.requestMonoWithMonoArg(Mono.just("A"), Mono.just("B"));
+ monoResult.doOnNext(new Consumer<String>() {
+ @Override
+ public void accept(String s) {
+ System.out.println(s);
+ }
+ }).block();
+
+ Flux<String> fluxResult = demoService.requestFluxWithFluxArg(Flux.just("A","B","C"), Flux.just("1","2","3"));
+ fluxResult.doOnNext(new Consumer<String>() {
+ @Override
+ public void accept(String s) {
+ System.out.println(s);
+ }
+ }).blockLast();
+
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/RsocketProvider.java b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/RsocketProvider.java
new file mode 100644
index 0000000..e093f73
--- /dev/null
+++ b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/RsocketProvider.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.basic;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class RsocketProvider {
+
+ public static void main(String[] args) throws Exception {
+ new EmbeddedZooKeeper(2181, false).start();
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/rsocket-provider.xml"});
+ context.start();
+
+ System.in.read(); // press any key to exit
+ }
+
+}
diff --git a/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/api/DemoService.java b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/api/DemoService.java
new file mode 100644
index 0000000..ff72a1c
--- /dev/null
+++ b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/api/DemoService.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.basic.api;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public interface DemoService {
+
+ String sayHello(String name);
+
+ Mono<String> requestMono(String name);
+
+ Mono<String> requestMonoBizError(String name);
+
+ Flux<String> requestFlux(String name);
+
+ Mono<String> requestMonoWithMonoArg(Mono<String> m1, Mono<String> m2);
+
+ Flux<String> requestFluxWithFluxArg(Flux<String> f1, Flux<String> f2);
+
+}
diff --git a/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java
new file mode 100644
index 0000000..eb8fd84
--- /dev/null
+++ b/dubbo-samples-rsocket/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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.samples.basic.api.DemoService;
+
+import com.alibaba.dubbo.rpc.RpcContext;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.FluxSink;
+import reactor.core.publisher.Mono;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.function.BiFunction;
+import java.util.function.Consumer;
+
+public class DemoServiceImpl implements DemoService {
+
+ 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();
+ }
+
+
+ public Mono<String> requestMono(String name) {
+ return Mono.just("hello " + name);
+ }
+
+ public Mono<String> requestMonoBizError(String name) {
+ int a = 1 / 0;
+ return Mono.just("hello " + name);
+ }
+
+ @Override
+ public Flux<String> requestFlux(String name) {
+
+ return Flux.create(new Consumer<FluxSink<String>>() {
+ @Override
+ public void accept(FluxSink<String> fluxSink) {
+ for (int i = 0; i < 5; i++) {
+ fluxSink.next(name + " " + i);
+ }
+ fluxSink.complete();
+ }
+ });
+
+ }
+
+ @Override
+ public Mono<String> requestMonoWithMonoArg(Mono<String> m1, Mono<String> m2) {
+ return m1.zipWith(m2, new BiFunction<String, String, String>() {
+ @Override
+ public String apply(String s, String s2) {
+ return s+" "+s2;
+ }
+ });
+ }
+
+ @Override
+ public Flux<String> requestFluxWithFluxArg(Flux<String> f1, Flux<String> f2) {
+ return f1.zipWith(f2, new BiFunction<String, String, String>() {
+ @Override
+ public String apply(String s, String s2) {
+ return s+" "+s2;
+ }
+ });
+ }
+
+}
diff --git a/dubbo-samples-rsocket/src/main/resources/log4j.properties b/dubbo-samples-rsocket/src/main/resources/log4j.properties
new file mode 100644
index 0000000..d6ecd5c
--- /dev/null
+++ b/dubbo-samples-rsocket/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/dubbo-samples-rsocket/src/main/resources/spring/rsocket-consumer.xml b/dubbo-samples-rsocket/src/main/resources/spring/rsocket-consumer.xml
new file mode 100644
index 0000000..8520469
--- /dev/null
+++ b/dubbo-samples-rsocket/src/main/resources/spring/rsocket-consumer.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+ <!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
+ don't set it same as provider -->
+ <dubbo:application name="demo-consumer"/>
+
+ <!-- use multicast registry center to discover service -->
+ <dubbo:registry group="aaa" address="zookeeper://127.0.0.1:2181"/>
+
+ <!-- generate proxy for the remote service, then demoService can be used in the same way as the
+ local regular interface -->
+ <dubbo:reference id="demoService" check="true" interface="org.apache.dubbo.samples.basic.api.DemoService"/>
+
+</beans>
\ No newline at end of file
diff --git a/dubbo-samples-rsocket/src/main/resources/spring/rsocket-provider.xml b/dubbo-samples-rsocket/src/main/resources/spring/rsocket-provider.xml
new file mode 100644
index 0000000..21369f0
--- /dev/null
+++ b/dubbo-samples-rsocket/src/main/resources/spring/rsocket-provider.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+ <!-- provider's application name, used for tracing dependency relationship -->
+ <dubbo:application name="demo-provider"/>
+
+ <!-- use multicast registry center to export service -->
+ <dubbo:registry group="aaa" address="zookeeper://127.0.0.1:2181"/>
+ <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
+ <!--<dubbo:registry address="zookeeper://11.163.250.27:2181"/>-->
+
+ <!-- use dubbo protocol to export service on port 20880 -->
+ <dubbo:protocol name="rsocket" port="20890"/>
+
+ <!-- service implementation, as same as regular local bean -->
+ <bean id="demoService" class="org.apache.dubbo.samples.basic.impl.DemoServiceImpl"/>
+
+ <!-- declare the service interface to be exported -->
+ <dubbo:service interface="org.apache.dubbo.samples.basic.api.DemoService" ref="demoService"/>
+
+</beans>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 060e35b..82a5d48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,6 +66,7 @@
<module>dubbo-samples-version</module>
<module>dubbo-samples-zipkin</module>
<module>dubbo-samples-zookeeper</module>
+ <module>dubbo-samples-rsocket</module>
</modules>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org