├── .gitignore ├── LICENSE.txt ├── README.md ├── rsocket-client ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── joshlong │ │ │ └── rsocket │ │ │ └── client │ │ │ ├── EnableRSocketClients.java │ │ │ ├── RSocketClient.java │ │ │ ├── RSocketClientAutoConfiguration.java │ │ │ ├── RSocketClientBuilder.java │ │ │ ├── RSocketClientFactoryBean.java │ │ │ └── RSocketClientsRegistrar.java │ └── resources │ │ └── META-INF │ │ └── spring.factories │ └── test │ ├── java │ └── com │ │ └── joshlong │ │ └── rsocket │ │ └── client │ │ ├── metadata │ │ ├── Constants.java │ │ ├── GreetingClient.java │ │ ├── GreetingResponse.java │ │ ├── GreetingsController.java │ │ ├── RSocketClientConfiguration.java │ │ ├── RSocketClientTest.java │ │ └── RSocketServerConfiguration.java │ │ ├── qualifiers │ │ ├── Constants.java │ │ ├── RSocketQualifierClientTest.java │ │ ├── greetings │ │ │ ├── Greeting.java │ │ │ ├── GreetingClient.java │ │ │ └── GreetingsController.java │ │ └── people │ │ │ ├── Person.java │ │ │ ├── PersonClient.java │ │ │ └── PersonController.java │ │ └── simple │ │ ├── GreetingClient.java │ │ ├── GreetingResponse.java │ │ ├── GreetingsController.java │ │ ├── RSocketClientConfiguration.java │ │ ├── RSocketClientTest.java │ │ └── RSocketServerConfiguration.java │ └── resources │ ├── application-service.properties │ └── application.properties └── samples └── hello ├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── example │ │ └── test │ │ ├── client │ │ └── TestApplication.java │ │ └── service │ │ └── TestApplication.java └── resources │ └── application.properties └── test └── java └── com └── example └── test └── TestApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A Feign-like RSocket Client 2 | 3 | ## Inspiration 4 | 5 | It'd be nice to have easy Feign-like RSocket clients. This is a thing [@Mario5Gray](http://github.com/Mario5Gray) has talked about, and it seems like a great idea. So here it is. 6 | 7 | ## Installation 8 | 9 | Add the following dependency to your build: 10 | 11 | ```xml 12 | 13 | com.joshlong.rsocket 14 | client 15 | 0.0.1-SNAPSHOT 16 | 17 | ``` 18 | 19 | In your Java code you need to enable the RSocket client support. Use the `@EnableRSocketClient` annotation. You'll also need to define an `RSocketRequester` bean. 20 | 21 | ```java 22 | @SpringBootApplication 23 | @EnableRSocketClient 24 | class RSocketClientApplication { 25 | 26 | @Bean RSocketRequester requester (RSocketRequester.Builder builder) { 27 | return builder.connectTcp("localhost", 8888).block(); 28 | } 29 | } 30 | 31 | ``` 32 | 33 | then, define an RSocket client interface, like this: 34 | 35 | 36 | ```java 37 | 38 | 39 | @RSocketClient 40 | public interface GreetingClient { 41 | 42 | @MessageMapping("supplier") 43 | Mono greet(); 44 | 45 | @MessageMapping("request-response") 46 | Mono requestResponse(Mono name); 47 | 48 | @MessageMapping("fire-and-forget") 49 | Mono fireAndForget(Mono name); 50 | 51 | @MessageMapping("destination.variables.and.payload.annotations.{name}.{age}") 52 | Mono greetMonoNameDestinationVariable( 53 | @DestinationVariable("name") String name, 54 | @DestinationVariable("age") int age, 55 | @Payload Mono payload); 56 | } 57 | 58 | ``` 59 | 60 | If you invoke methods on this interface it'll in turn invoke endpoints using the configured `RSocketRequester` for you, turning destination variables into route variables and turning your payload into the data for the request. 61 | 62 | 63 | ## Mapping Headers (RSocket metadata) to the RSocket request 64 | 65 | You can map `@Header` elements to parameters in the method invocation. The header parameters get sent as composite RSocket metadata. Normal invocations of RSocket metadata would require two parts - a mime type and a value tht can be encoded. The encoding is a separate issue - Spring ships with a ton of encoders/decoders out of the box, but by default Spring Framework's built in support uses something called `CBOR`. There is still the question of how to communicate the mimetype. We expect the mime-type to be specified as the `value()` attribute for the `@Header` annotation. Thus: 66 | 67 | ```java 68 | import com.joshlong.rsocket.client.RSocketClient; 69 | import org.springframework.messaging.handler.annotation.Header; 70 | import org.springframework.messaging.handler.annotation.MessageMapping; 71 | import org.springframework.messaging.handler.annotation.Payload; 72 | import reactor.core.publisher.Mono; 73 | 74 | @RSocketClient 75 | interface GreetingClient { 76 | 77 | @MessageMapping("greetings") 78 | Mono greet(@Header( "messaging/x.bootiful.client-id") String clientId, @Payload Mono name); 79 | 80 | } 81 | ``` 82 | 83 | This needs to line up with the expectations for composite metadata on the responder side of course. 84 | 85 | 86 | 87 | 88 | ## Pairing `RSocketRequesters` to `@RSocketClient` interfaces 89 | 90 | You can annotate your interfaces with a `@Qualifier` annotation (or a meta-annotated qualifier of your own making ) and then annotate an `RSocketRequester` and this module will use that `RSocketRequester` when servicing methods on a particular interface. 91 | 92 | The following demonstrates the concept in action. RSocket connections are stateful. Once they've connected, they stay connected and all subsequent interactions are assumed to be against the already established connection. Therefore, each `RSocketRequester` talks to a different logical (and physical) service, unlike, e.g., a `WebClient` which may be used to talk to any arbitrary host and port. 93 | 94 | ```java 95 | 96 | @RSocketClient 97 | @Qualifier(Constants.QUALIFIER_2) 98 | interface GreetingClient { 99 | 100 | @MessageMapping("greetings-with-name") 101 | Mono greet(Mono name); 102 | 103 | } 104 | 105 | @RSocketClient 106 | @PersonQualifier 107 | interface PersonClient { 108 | 109 | @MessageMapping("people") 110 | Flux people(); 111 | 112 | } 113 | 114 | @EnableRSocketClients 115 | @SpringBootApplication 116 | class RSocketClientConfiguration { 117 | 118 | @Bean 119 | @PersonQualifier // meta-annotation 120 | // @Qualifier(Constants.QUALIFIER_1) 121 | RSocketRequester one(@Value("${" + Constants.QUALIFIER_1 + ".port}") int port, RSocketRequester.Builder builder) { 122 | return builder.connectTcp("localhost", port).block(); 123 | } 124 | 125 | 126 | @Bean 127 | @Qualifier(Constants.QUALIFIER_2) // direct-annotation 128 | RSocketRequester two(@Value("${" + Constants.QUALIFIER_2 + ".port}") int port, RSocketRequester.Builder builder) { 129 | return builder.connectTcp("localhost", port).block(); 130 | } 131 | 132 | } 133 | 134 | @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER }) 135 | @Retention(RetentionPolicy.RUNTIME) 136 | @Qualifier(Constants.QUALIFIER_1) 137 | @interface PersonQualifier { 138 | } 139 | 140 | ``` 141 | 142 | -------------------------------------------------------------------------------- /rsocket-client/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.6"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /rsocket-client/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshlong-attic/a-feign-like-rsocket-client/97dd1dfa5c89379105b4853fa2f0abe041d9692a/rsocket-client/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /rsocket-client/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /rsocket-client/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /rsocket-client/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /rsocket-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.3.1.RELEASE 9 | 10 | 11 | com.joshlong.rsocket 12 | client 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 8 17 | 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-rsocket 23 | 24 | 25 | org.projectlombok 26 | lombok 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-test 31 | test 32 | 33 | 34 | org.junit.vintage 35 | junit-vintage-engine 36 | 37 | 38 | 39 | 40 | io.projectreactor 41 | reactor-test 42 | test 43 | 44 | 45 | 46 | 47 | 48 | 49 | io.spring.javaformat 50 | spring-javaformat-maven-plugin 51 | 0.0.23 52 | 53 | 54 | validate 55 | true 56 | 57 | validate 58 | 59 | 60 | 61 | 62 | 63 | org.jfrog.buildinfo 64 | artifactory-maven-plugin 65 | 66 | 2.4.0 67 | 68 | false 69 | 70 | 71 | build-info 72 | 73 | publish 74 | 75 | 76 | 77 | {{TRAVIS_COMMIT}} 78 | 79 | 80 | 81 | 82 | https://cloudnativejava.jfrog.io/cloudnativejava 83 | 84 | ${env.ARTIFACTORY_USERNAME} 85 | ${env.ARTIFACTORY_PASSWORD} 86 | libs-release-local 87 | libs-snapshot-local 88 | 89 | 90 | 91 | Travis CI 92 | {{TRAVIS_BUILD_NUMBER}} 93 | 94 | 95 | http://travis-ci.org/{{TRAVIS_REPO_SLUG}}/builds/{{TRAVIS_BUILD_ID}} 96 | 97 | {{USER}} 98 | {{TRAVIS_COMMIT}} 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | false 110 | 111 | central 112 | libs-release 113 | 114 | https://cloudnativejava.jfrog.io/cloudnativejava/libs-release 115 | 116 | 117 | 118 | 119 | snapshots 120 | libs-snapshot 121 | 122 | https://cloudnativejava.jfrog.io/cloudnativejava/libs-snapshot 123 | 124 | 125 | 126 | 127 | 128 | 129 | false 130 | 131 | central 132 | plugins-release 133 | 134 | https://cloudnativejava.jfrog.io/cloudnativejava/plugins-release 135 | 136 | 137 | 138 | 139 | snapshots 140 | plugins-snapshot 141 | 142 | https://cloudnativejava.jfrog.io/cloudnativejava/plugins-snapshot 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /rsocket-client/src/main/java/com/joshlong/rsocket/client/EnableRSocketClients.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client; 2 | 3 | import org.springframework.context.annotation.Import; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * @author Josh Long 9 | */ 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Target(ElementType.TYPE) 12 | @Documented 13 | @Import(RSocketClientsRegistrar.class) 14 | public @interface EnableRSocketClients { 15 | 16 | String[] value() default {}; 17 | 18 | String[] basePackages() default {}; 19 | 20 | Class[] basePackageClasses() default {}; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /rsocket-client/src/main/java/com/joshlong/rsocket/client/RSocketClient.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * @author Josh Long 7 | */ 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Documented 11 | @Inherited 12 | public @interface RSocketClient { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /rsocket-client/src/main/java/com/joshlong/rsocket/client/RSocketClientAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.messaging.rsocket.RSocketRequester; 8 | 9 | /** 10 | * @author Josh Long 11 | */ 12 | @Log4j2 13 | @Configuration 14 | class RSocketClientAutoConfiguration { 15 | 16 | @Bean 17 | @ConditionalOnBean(RSocketRequester.class) 18 | RSocketClientBuilder rSocketClientBuilder() { 19 | return new RSocketClientBuilder(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /rsocket-client/src/main/java/com/joshlong/rsocket/client/RSocketClientBuilder.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | import lombok.extern.log4j.Log4j2; 5 | import org.aopalliance.intercept.MethodInterceptor; 6 | import org.springframework.aop.framework.ProxyFactoryBean; 7 | import org.springframework.core.ResolvableType; 8 | import org.springframework.messaging.handler.annotation.DestinationVariable; 9 | import org.springframework.messaging.handler.annotation.Header; 10 | import org.springframework.messaging.handler.annotation.MessageMapping; 11 | import org.springframework.messaging.handler.annotation.Payload; 12 | import org.springframework.messaging.rsocket.RSocketRequester; 13 | import org.springframework.util.Assert; 14 | import org.springframework.util.MimeType; 15 | import org.springframework.util.MimeTypeUtils; 16 | import org.springframework.util.StringUtils; 17 | import reactor.core.publisher.Flux; 18 | import reactor.core.publisher.Mono; 19 | 20 | import java.lang.reflect.Method; 21 | import java.lang.reflect.Parameter; 22 | import java.util.*; 23 | 24 | /** 25 | * @author Josh Long 26 | */ 27 | @Log4j2 28 | @RequiredArgsConstructor 29 | class RSocketClientBuilder { 30 | 31 | private static Object[] findDestinationVariables(Object[] arguments, Parameter[] parameters) { 32 | List destinationVariableValues = new ArrayList<>(); 33 | for (int i = 0; i < arguments.length; i++) { 34 | Parameter parameter = parameters[i]; 35 | Object arg = arguments[i]; 36 | if (parameter.getAnnotationsByType(DestinationVariable.class).length > 0) { 37 | destinationVariableValues.add(arg); 38 | } 39 | } 40 | return destinationVariableValues.toArray(new Object[0]); 41 | } 42 | 43 | private static Object findPayloadArgument(Object[] arguments, Parameter[] parameters) { 44 | Object payloadArgument = Mono.empty(); 45 | if (arguments.length == 0) { 46 | payloadArgument = Mono.empty(); 47 | } 48 | else if (arguments.length == 1) { 49 | payloadArgument = arguments[0]; 50 | } 51 | else { 52 | Assert.isTrue(parameters.length == arguments.length, 53 | "there should be " + "an equal number of " + Parameter.class.getName() + " and objects"); 54 | for (int i = 0; i < parameters.length; i++) { 55 | Parameter annotations = parameters[i]; 56 | Object argument = arguments[i]; 57 | if (annotations.getAnnotationsByType(Payload.class).length > 0) { 58 | payloadArgument = argument; 59 | } 60 | } 61 | } 62 | Assert.notNull(payloadArgument, 63 | "you must specify a @" + Payload.class.getName() + " parameter OR just one parameter"); 64 | return payloadArgument; 65 | } 66 | 67 | private static Map findCompositeMetadata(Object[] arguments, Parameter[] parameters) { 68 | Map metadata = new HashMap<>(); 69 | Assert.isTrue(parameters.length == arguments.length, 70 | "there should be an equal number of " + Parameter.class.getName() + " and objects"); 71 | for (int i = 0; i < parameters.length; i++) { 72 | Parameter annotations = parameters[i]; 73 | Object argument = arguments[i]; 74 | Header[] headers = annotations.getAnnotationsByType(Header.class); 75 | if (headers.length > 0) { 76 | Header header = headers[0]; 77 | Assert.state(StringUtils.hasText(header.value()) || StringUtils.hasText(header.name()), 78 | () -> "you can not use the @" + Header.class.getName() 79 | + " annotation unless you provide a mimetype"); 80 | MimeType mimeType = MimeTypeUtils.parseMimeType(header.value()); 81 | metadata.put(mimeType, argument); 82 | } 83 | } 84 | return metadata; 85 | } 86 | 87 | public T buildClientFor(Class clazz, RSocketRequester rSocketRequester) { 88 | Assert.notNull(rSocketRequester, "the requester must not be null"); 89 | Assert.notNull(clazz, "the Class must not be null"); 90 | ProxyFactoryBean pfb = new ProxyFactoryBean(); 91 | pfb.setTargetClass(clazz); 92 | pfb.addInterface(clazz); 93 | pfb.setAutodetectInterfaces(true); 94 | pfb.addAdvice((MethodInterceptor) methodInvocation -> { 95 | Method method = methodInvocation.getMethod(); 96 | String methodName = method.getName(); 97 | Class returnType = method.getReturnType(); 98 | Object[] arguments = methodInvocation.getArguments(); 99 | Parameter[] parameters = method.getParameters(); 100 | MessageMapping annotation = method.getAnnotation(MessageMapping.class); 101 | String route = annotation.value()[0]; 102 | ResolvableType resolvableType = ResolvableType.forMethodReturnType(method); 103 | Class rawClassForReturnType = resolvableType.getGenerics()[0].getRawClass(); 104 | Object[] routeArguments = findDestinationVariables(arguments, parameters); 105 | Object payloadArgument = findPayloadArgument(arguments, parameters); 106 | Map compositeMetadata = findCompositeMetadata(arguments, parameters); 107 | 108 | if (log.isDebugEnabled()) { 109 | log.debug("invoking " + methodName + " accepting " + arguments.length + " argument(s) for route " 110 | + route + " with destination variables (" 111 | + StringUtils.arrayToDelimitedString(routeArguments, ", ") + ")" + '.' + " The payload is " 112 | + payloadArgument); 113 | } 114 | 115 | if (Mono.class.isAssignableFrom(returnType)) { 116 | // special case for fire-and-forget 117 | if (Void.class.isAssignableFrom(rawClassForReturnType)) { 118 | if (log.isDebugEnabled()) { 119 | log.debug("fire-and-forget"); 120 | } 121 | return enrichMetadata(rSocketRequester.route(route, routeArguments), compositeMetadata) 122 | .data(payloadArgument)// 123 | .send(); 124 | } 125 | else { 126 | if (log.isDebugEnabled()) { 127 | log.debug("request-response"); 128 | } 129 | return enrichMetadata(rSocketRequester.route(route, routeArguments), compositeMetadata)// 130 | .data(payloadArgument)// 131 | .retrieveMono(rawClassForReturnType); 132 | } 133 | } 134 | 135 | if (Flux.class.isAssignableFrom(returnType)) { 136 | if (log.isDebugEnabled()) { 137 | log.debug("request-stream or channel"); 138 | } 139 | return enrichMetadata(rSocketRequester.route(route, routeArguments), compositeMetadata) 140 | .data(payloadArgument).retrieveFlux(rawClassForReturnType); 141 | } 142 | // is there something more sensible to return? 143 | return Mono.empty(); 144 | }); 145 | 146 | return (T) pfb.getObject(); 147 | } 148 | 149 | private RSocketRequester.RequestSpec enrichMetadata(RSocketRequester.RequestSpec route, 150 | Map compositeMetadata) { 151 | if (!compositeMetadata.isEmpty()) { 152 | for (Map.Entry entry : compositeMetadata.entrySet()) { 153 | route = route.metadata(entry.getValue(), entry.getKey()); 154 | } 155 | } 156 | 157 | return route; 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /rsocket-client/src/main/java/com/joshlong/rsocket/client/RSocketClientFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client; 2 | 3 | import lombok.SneakyThrows; 4 | import lombok.extern.log4j.Log4j2; 5 | import org.springframework.beans.BeansException; 6 | import org.springframework.beans.factory.BeanFactory; 7 | import org.springframework.beans.factory.BeanFactoryAware; 8 | import org.springframework.beans.factory.FactoryBean; 9 | import org.springframework.beans.factory.ListableBeanFactory; 10 | import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils; 11 | import org.springframework.beans.factory.annotation.Qualifier; 12 | import org.springframework.core.annotation.MergedAnnotation; 13 | import org.springframework.core.annotation.MergedAnnotations; 14 | import org.springframework.messaging.rsocket.RSocketRequester; 15 | import org.springframework.util.Assert; 16 | 17 | import java.util.Map; 18 | 19 | /** 20 | * @author Josh Long 21 | */ 22 | @Log4j2 23 | class RSocketClientFactoryBean implements BeanFactoryAware, FactoryBean { 24 | 25 | private Class type; 26 | 27 | private ListableBeanFactory context; 28 | 29 | private static RSocketRequester forInterface(Class clientInterface, ListableBeanFactory context) { 30 | Map rSocketRequestersInContext = context.getBeansOfType(RSocketRequester.class); 31 | int rSocketRequestersCount = rSocketRequestersInContext.size(); 32 | Assert.state(rSocketRequestersCount > 0, () -> "there should be at least one " 33 | + RSocketRequester.class.getName() + " in the context. Please consider defining one."); 34 | RSocketRequester rSocketRequester = null; 35 | Assert.notNull(clientInterface, "the client interface must be non-null"); 36 | Assert.notNull(context, () -> "the " + ListableBeanFactory.class.getName() + " interface must be non-null"); 37 | MergedAnnotation qualifier = MergedAnnotations.from(clientInterface).get(Qualifier.class); 38 | if (qualifier.isPresent()) { 39 | String valueOfQualifierAnnotation = qualifier.getString(MergedAnnotation.VALUE); 40 | Map beans = BeanFactoryAnnotationUtils.qualifiedBeansOfType(context, 41 | RSocketRequester.class, valueOfQualifierAnnotation); 42 | Assert.state(beans.size() == 1, 43 | () -> "I need just one " + RSocketRequester.class.getName() + " but I got " + beans.keySet()); 44 | for (Map.Entry entry : beans.entrySet()) { 45 | rSocketRequester = entry.getValue(); 46 | if (log.isDebugEnabled()) { 47 | log.debug("found " + rSocketRequester + " with bean name " + entry.getKey() + " for @" 48 | + RSocketClient.class.getName() + " interface " + clientInterface.getName() + '.'); 49 | } 50 | } 51 | } 52 | else { 53 | Assert.state(rSocketRequestersCount == 1, () -> "there should be no more and no less than one unqualified " 54 | + RSocketRequester.class.getName() + " instances in the context."); 55 | return rSocketRequestersInContext.values().iterator().next(); 56 | } 57 | Assert.notNull(rSocketRequester, () -> "we could not find an " + RSocketRequester.class.getName() 58 | + " for the @RSocketClient interface " + clientInterface.getName() + '.'); 59 | return rSocketRequester; 60 | } 61 | 62 | @SneakyThrows 63 | public void setType(String type) { 64 | this.type = Class.forName(type); 65 | } 66 | 67 | @Override 68 | public Object getObject() { 69 | RSocketRequester rSocketRequester = forInterface(this.type, this.context); 70 | RSocketClientBuilder clientBuilder = this.context.getBean(RSocketClientBuilder.class); 71 | return clientBuilder.buildClientFor(this.type, rSocketRequester); 72 | } 73 | 74 | @Override 75 | public Class getObjectType() { 76 | return this.type; 77 | } 78 | 79 | @Override 80 | public void setBeanFactory(BeanFactory beanFactory) throws BeansException { 81 | Assert.state(beanFactory instanceof ListableBeanFactory, 82 | () -> "the BeanFactory is not an instance of a ListableBeanFactory"); 83 | this.context = (ListableBeanFactory) beanFactory; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /rsocket-client/src/main/java/com/joshlong/rsocket/client/RSocketClientsRegistrar.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client; 2 | 3 | import lombok.SneakyThrows; 4 | import lombok.extern.log4j.Log4j2; 5 | import org.springframework.beans.BeansException; 6 | import org.springframework.beans.factory.BeanFactory; 7 | import org.springframework.beans.factory.BeanFactoryAware; 8 | import org.springframework.beans.factory.FactoryBean; 9 | import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; 10 | import org.springframework.beans.factory.config.BeanDefinitionHolder; 11 | import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 12 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 13 | import org.springframework.beans.factory.support.*; 14 | import org.springframework.boot.autoconfigure.AutoConfigurationPackages; 15 | import org.springframework.context.EnvironmentAware; 16 | import org.springframework.context.ResourceLoaderAware; 17 | import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; 18 | import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; 19 | import org.springframework.core.env.Environment; 20 | import org.springframework.core.io.ResourceLoader; 21 | import org.springframework.core.type.AnnotationMetadata; 22 | import org.springframework.core.type.StandardAnnotationMetadata; 23 | import org.springframework.core.type.filter.AnnotationTypeFilter; 24 | import org.springframework.messaging.handler.annotation.MessageMapping; 25 | import org.springframework.util.Assert; 26 | import org.springframework.util.ClassUtils; 27 | import org.springframework.util.ReflectionUtils; 28 | import org.springframework.util.StringUtils; 29 | 30 | import java.util.*; 31 | 32 | /** 33 | * @author Josh Long 34 | */ 35 | @Log4j2 36 | class RSocketClientsRegistrar implements BeanFactoryPostProcessor, ImportBeanDefinitionRegistrar, BeanFactoryAware, 37 | EnvironmentAware, ResourceLoaderAware { 38 | 39 | private BeanFactory beanFactory; 40 | 41 | private Environment environment; 42 | 43 | private ResourceLoader resourceLoader; 44 | 45 | private Set getBasePackages(AnnotationMetadata importingClassMetadata) { 46 | Map attributes = importingClassMetadata 47 | .getAnnotationAttributes(EnableRSocketClients.class.getCanonicalName()); 48 | 49 | Set basePackages = new HashSet<>(); 50 | for (String pkg : (String[]) attributes.get("value")) { 51 | if (StringUtils.hasText(pkg)) { 52 | basePackages.add(pkg); 53 | } 54 | } 55 | for (String pkg : (String[]) attributes.get("basePackages")) { 56 | if (StringUtils.hasText(pkg)) { 57 | basePackages.add(pkg); 58 | } 59 | } 60 | for (Class clazz : (Class[]) attributes.get("basePackageClasses")) { 61 | basePackages.add(ClassUtils.getPackageName(clazz)); 62 | } 63 | 64 | if (basePackages.isEmpty()) { 65 | basePackages.add(ClassUtils.getPackageName(importingClassMetadata.getClassName())); 66 | } 67 | return basePackages; 68 | } 69 | 70 | @Override 71 | public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, 72 | BeanNameGenerator importBeanNameGenerator) { 73 | Collection basePackages = getBasePackages(importingClassMetadata); 74 | if (log.isDebugEnabled()) { 75 | log.debug("scanning the following packages: " 76 | + StringUtils.arrayToDelimitedString(basePackages.toArray(new String[0]), ", ")); 77 | } 78 | ClassPathScanningCandidateComponentProvider scanner = this.buildScanner(); 79 | basePackages.forEach(basePackage -> scanner.findCandidateComponents(basePackage)// 80 | .stream()// 81 | .filter(cc -> cc instanceof AnnotatedBeanDefinition)// 82 | .map(abd -> (AnnotatedBeanDefinition) abd)// 83 | .forEach(beanDefinition -> { 84 | AnnotationMetadata annotationMetadata = beanDefinition.getMetadata(); 85 | this.validateInterface(annotationMetadata); 86 | this.registerRSocketClient(annotationMetadata, registry); 87 | })); 88 | } 89 | 90 | @SneakyThrows 91 | private void validateInterface(AnnotationMetadata annotationMetadata) { 92 | Assert.isTrue(annotationMetadata.isInterface(), 93 | "the @" + RSocketClient.class.getName() + " annotation must be used only on an interface"); 94 | Class clzz = Class.forName(annotationMetadata.getClassName()); 95 | ReflectionUtils.doWithMethods(clzz, method -> { 96 | if (log.isDebugEnabled()) { 97 | log.debug("validating " + clzz.getName() + "#" + method.getName()); 98 | } 99 | MessageMapping annotation = method.getAnnotation(MessageMapping.class); 100 | Assert.notNull(annotation, "you must use the @" + MessageMapping.class.getName() 101 | + " annotation on every method on " + clzz.getName() + '.'); 102 | }); 103 | } 104 | 105 | private ClassPathScanningCandidateComponentProvider buildScanner() { 106 | ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false, 107 | this.environment) { 108 | @Override 109 | protected boolean isCandidateComponent(AnnotatedBeanDefinition metadata) { 110 | return metadata.getMetadata().isIndependent() && !metadata.getMetadata().isAnnotation(); 111 | } 112 | }; 113 | scanner.addIncludeFilter(new AnnotationTypeFilter(RSocketClient.class)); 114 | scanner.setResourceLoader(this.resourceLoader); 115 | return scanner; 116 | } 117 | 118 | @Override 119 | public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { 120 | } 121 | 122 | @SneakyThrows 123 | private void registerRSocketClient(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) { 124 | String className = annotationMetadata.getClassName(); 125 | if (log.isDebugEnabled()) { 126 | log.debug("trying to turn the interface " + className + " into an RSocketClientFactoryBean"); 127 | } 128 | 129 | BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(RSocketClientFactoryBean.class); 130 | definition.addPropertyValue("type", className); 131 | definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); 132 | 133 | AbstractBeanDefinition beanDefinition = definition.getBeanDefinition(); 134 | beanDefinition.setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, className); 135 | beanDefinition.setPrimary(true); 136 | 137 | BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className, new String[0]); 138 | BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); 139 | } 140 | 141 | @Override 142 | public void setResourceLoader(ResourceLoader resourceLoader) { 143 | this.resourceLoader = resourceLoader; 144 | } 145 | 146 | @Override 147 | public void setEnvironment(Environment environment) { 148 | this.environment = environment; 149 | } 150 | 151 | @Override 152 | public void setBeanFactory(BeanFactory beanFactory) throws BeansException { 153 | this.beanFactory = beanFactory; 154 | } 155 | 156 | @Override 157 | public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 158 | // log.info("postProcessBeanFactory"); 159 | // why does this never get called? 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /rsocket-client/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.joshlong.rsocket.client.RSocketClientAutoConfiguration -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/metadata/Constants.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.metadata; 2 | 3 | import org.springframework.util.MimeType; 4 | 5 | class Constants { 6 | 7 | public static final String CLIENT_ID_HEADER = "client-id"; 8 | 9 | public static final String LANG_HEADER = "lang"; 10 | 11 | public static final String CLIENT_ID_MIME_TYPE_VALUE = "messaging/x.bootiful." + CLIENT_ID_HEADER; 12 | 13 | public static final String LANG_MIME_TYPE_VALUE = "messaging/x.bootiful." + LANG_HEADER; 14 | 15 | public static final MimeType CLIENT_ID_MIME_TYPE = MimeType.valueOf(CLIENT_ID_MIME_TYPE_VALUE); 16 | 17 | public static final MimeType LANG_MIME_TYPE = MimeType.valueOf(LANG_MIME_TYPE_VALUE); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/metadata/GreetingClient.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.metadata; 2 | 3 | import com.joshlong.rsocket.client.RSocketClient; 4 | import org.springframework.messaging.handler.annotation.Header; 5 | import org.springframework.messaging.handler.annotation.MessageMapping; 6 | import org.springframework.messaging.handler.annotation.Payload; 7 | import reactor.core.publisher.Mono; 8 | 9 | import java.util.Map; 10 | 11 | @RSocketClient 12 | interface GreetingClient { 13 | 14 | @MessageMapping("greetings") 15 | Mono> greet(@Header(Constants.CLIENT_ID_MIME_TYPE_VALUE) String clientId, 16 | @Payload Mono name); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/metadata/GreetingResponse.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.metadata; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class GreetingResponse { 11 | 12 | private String message; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/metadata/GreetingsController.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.metadata; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.springframework.context.annotation.Profile; 5 | import org.springframework.messaging.handler.annotation.Headers; 6 | import org.springframework.messaging.handler.annotation.MessageMapping; 7 | import org.springframework.messaging.handler.annotation.Payload; 8 | import org.springframework.stereotype.Controller; 9 | import reactor.core.publisher.Mono; 10 | 11 | import java.util.Collections; 12 | import java.util.Map; 13 | 14 | @Log4j2 15 | @Profile("service") 16 | @Controller 17 | class GreetingsController { 18 | 19 | @MessageMapping("greetings") 20 | Mono> greet(@Headers Map headers, @Payload Mono in) { 21 | headers.forEach((k, v) -> log.info(k + '=' + v)); 22 | Map data = Collections.singletonMap(Constants.CLIENT_ID_MIME_TYPE_VALUE, 23 | headers.get(Constants.CLIENT_ID_HEADER)); 24 | return Mono.just(data); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/metadata/RSocketClientConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.metadata; 2 | 3 | import com.joshlong.rsocket.client.EnableRSocketClients; 4 | import lombok.extern.log4j.Log4j2; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Profile; 9 | import org.springframework.messaging.rsocket.RSocketRequester; 10 | 11 | import javax.annotation.PostConstruct; 12 | 13 | @Log4j2 14 | @Profile("client") 15 | @EnableRSocketClients 16 | @SpringBootApplication 17 | class RSocketClientConfiguration { 18 | 19 | @Bean 20 | RSocketRequester rSocketRequester(@Value("${service.port}") int port, RSocketRequester.Builder builder) { 21 | return builder.connectTcp("localhost", port).block(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/metadata/RSocketClientTest.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.metadata; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.WebApplicationType; 6 | import org.springframework.boot.builder.SpringApplicationBuilder; 7 | import org.springframework.context.ConfigurableApplicationContext; 8 | import org.springframework.messaging.rsocket.RSocketRequester; 9 | import org.springframework.util.SocketUtils; 10 | import reactor.core.publisher.Mono; 11 | import reactor.test.StepVerifier; 12 | 13 | @Log4j2 14 | public class RSocketClientTest { 15 | 16 | @Test 17 | public void monoInAndOut() { 18 | int servicePort = SocketUtils.findAvailableTcpPort(); 19 | ConfigurableApplicationContext service = runService(servicePort); 20 | ConfigurableApplicationContext client = runClient(servicePort); 21 | RSocketRequester rSocketRequester = client.getBean(RSocketRequester.class); 22 | GreetingClient gc = client.getBean(GreetingClient.class); 23 | StepVerifier.create(gc.greet("123", Mono.just("A Name"))) 24 | .expectNextMatches( 25 | map -> map.containsKey(Constants.CLIENT_ID_MIME_TYPE_VALUE) && map.containsValue("123")) 26 | .verifyComplete(); 27 | client.stop(); 28 | service.stop(); 29 | } 30 | 31 | private static ConfigurableApplicationContext runService(int port) { 32 | return new SpringApplicationBuilder(RSocketServerConfiguration.class)// 33 | .web(WebApplicationType.NONE) 34 | .run("--spring.profiles.active=service", "--spring.rsocket.server.port=" + port); 35 | } 36 | 37 | private ConfigurableApplicationContext runClient(int port) { 38 | ConfigurableApplicationContext context = new SpringApplicationBuilder(RSocketClientConfiguration.class)// 39 | .web(WebApplicationType.NONE)// 40 | .run("--service.port=" + port, "--spring.profiles.active=client"); 41 | return context; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/metadata/RSocketServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.metadata; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.Profile; 9 | import org.springframework.core.codec.StringDecoder; 10 | import org.springframework.util.MimeType; 11 | 12 | import javax.annotation.PostConstruct; 13 | 14 | @Log4j2 15 | @Profile("service") 16 | @Configuration 17 | @EnableAutoConfiguration 18 | class RSocketServerConfiguration { 19 | 20 | @Bean 21 | RSocketStrategiesCustomizer rSocketStrategiesCustomizer() { 22 | return strategies -> strategies// 23 | .metadataExtractorRegistry(registry -> { 24 | registry.metadataToExtract(Constants.CLIENT_ID_MIME_TYPE, String.class, Constants.CLIENT_ID_HEADER); 25 | registry.metadataToExtract(Constants.LANG_MIME_TYPE, String.class, Constants.LANG_HEADER); 26 | })// 27 | .decoders(decoders -> decoders.add(StringDecoder.allMimeTypes())); 28 | } 29 | 30 | @Bean 31 | GreetingsController greetingsController() { 32 | return new GreetingsController(); 33 | } 34 | 35 | @PostConstruct 36 | public void start() { 37 | log.info("starting " + RSocketServerConfiguration.class.getName() + '.'); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/qualifiers/Constants.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.qualifiers; 2 | 3 | public class Constants { 4 | 5 | public final static String QUALIFIER_1 = "service1"; 6 | 7 | public final static String QUALIFIER_2 = "service2"; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/qualifiers/RSocketQualifierClientTest.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.qualifiers; 2 | 3 | import com.joshlong.rsocket.client.EnableRSocketClients; 4 | import com.joshlong.rsocket.client.qualifiers.greetings.GreetingClient; 5 | import com.joshlong.rsocket.client.qualifiers.greetings.GreetingsController; 6 | import com.joshlong.rsocket.client.qualifiers.people.PersonClient; 7 | import com.joshlong.rsocket.client.qualifiers.people.PersonController; 8 | import lombok.extern.log4j.Log4j2; 9 | import org.junit.jupiter.api.AfterAll; 10 | import org.junit.jupiter.api.BeforeAll; 11 | import org.junit.jupiter.api.Test; 12 | import org.springframework.beans.factory.annotation.Qualifier; 13 | import org.springframework.beans.factory.annotation.Value; 14 | import org.springframework.boot.WebApplicationType; 15 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 16 | import org.springframework.boot.autoconfigure.SpringBootApplication; 17 | import org.springframework.boot.builder.SpringApplicationBuilder; 18 | import org.springframework.context.ConfigurableApplicationContext; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.context.annotation.Profile; 22 | import org.springframework.messaging.rsocket.RSocketRequester; 23 | import org.springframework.util.Assert; 24 | import org.springframework.util.SocketUtils; 25 | import reactor.core.publisher.Mono; 26 | import reactor.test.StepVerifier; 27 | 28 | import java.lang.annotation.ElementType; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.RetentionPolicy; 31 | import java.lang.annotation.Target; 32 | 33 | @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER }) 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Qualifier(Constants.QUALIFIER_1) 36 | @interface PersonQualifier { 37 | 38 | } 39 | 40 | @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER }) 41 | @Retention(RetentionPolicy.RUNTIME) 42 | @Qualifier(Constants.QUALIFIER_2) 43 | @interface GreetingQualifier { 44 | 45 | } 46 | 47 | @Log4j2 48 | public class RSocketQualifierClientTest { 49 | 50 | private static final int port1 = SocketUtils.findAvailableTcpPort(); 51 | 52 | private static final int port2 = SocketUtils.findAvailableTcpPort(); 53 | static String SERVICE_1 = Constants.QUALIFIER_1; 54 | static String SERVICE_2 = Constants.QUALIFIER_2; 55 | static ConfigurableApplicationContext serviceApplicationContext1; 56 | static ConfigurableApplicationContext serviceApplicationContext2; 57 | 58 | private static ConfigurableApplicationContext runServer(Class clzz, String profileName, int port) { 59 | return new SpringApplicationBuilder(clzz)// 60 | .web(WebApplicationType.NONE)// 61 | .run("--spring.profiles.active=" + profileName, "--spring.rsocket.server.port=" + port); 62 | } 63 | 64 | @BeforeAll 65 | public static void begin() { 66 | serviceApplicationContext1 = runServer(PeopleServerConfiguration.class, SERVICE_1, port1); 67 | serviceApplicationContext2 = runServer(GreetingServiceConfiguration.class, SERVICE_2, port2); 68 | } 69 | 70 | @AfterAll 71 | public static void destroy() { 72 | serviceApplicationContext1.stop(); 73 | serviceApplicationContext2.stop(); 74 | } 75 | 76 | @Test 77 | public void noValueInMonoOut() { 78 | ConfigurableApplicationContext svc = buildClient(); 79 | PersonClient personClient = svc.getBean(PersonClient.class); 80 | GreetingClient greetingClient = svc.getBean(GreetingClient.class); 81 | Assert.notNull(personClient, "the " + PersonClient.class.getName() + " is not null"); 82 | Assert.notNull(greetingClient, "the " + GreetingClient.class.getName() + " is not null"); 83 | 84 | StepVerifier.create(greetingClient.greetMono(Mono.just("Spring"))).expectNextCount(1).verifyComplete(); 85 | StepVerifier.create(personClient.people()).expectNextCount(4).verifyComplete(); 86 | } 87 | 88 | private ConfigurableApplicationContext buildClient() { 89 | return new SpringApplicationBuilder(RSocketClientConfiguration.class)// 90 | .web(WebApplicationType.NONE)// 91 | .run("--service1.port=" + port1, "--service2.port=" + port2, "--spring.profiles.active=client"); 92 | } 93 | 94 | } 95 | 96 | @Profile("client") 97 | @EnableRSocketClients 98 | @SpringBootApplication 99 | class RSocketClientConfiguration { 100 | 101 | // people 102 | @Bean 103 | @PersonQualifier 104 | // @Qualifier(Constants.QUALIFIER_1) 105 | RSocketRequester one(@Value("${" + Constants.QUALIFIER_1 + ".port}") int port, RSocketRequester.Builder builder) { 106 | return builder.connectTcp("localhost", port).block(); 107 | } 108 | 109 | // greetings 110 | @Bean 111 | @Qualifier(Constants.QUALIFIER_2) 112 | // @GreetingQualifier 113 | RSocketRequester two(@Value("${" + Constants.QUALIFIER_2 + ".port}") int port, RSocketRequester.Builder builder) { 114 | return builder.connectTcp("localhost", port).block(); 115 | } 116 | 117 | } 118 | 119 | @Log4j2 120 | @Profile("service1") 121 | @Configuration 122 | @EnableAutoConfiguration 123 | class PeopleServerConfiguration { 124 | 125 | @Bean 126 | PersonController personController() { 127 | return new PersonController(); 128 | } 129 | 130 | } 131 | 132 | @Log4j2 133 | @Profile("service2") 134 | @Configuration 135 | @EnableAutoConfiguration 136 | class GreetingServiceConfiguration { 137 | 138 | @Bean 139 | GreetingsController greetingsController() { 140 | return new GreetingsController(); 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/qualifiers/greetings/Greeting.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.qualifiers.greetings; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class Greeting { 11 | 12 | private String message; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/qualifiers/greetings/GreetingClient.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.qualifiers.greetings; 2 | 3 | import com.joshlong.rsocket.client.RSocketClient; 4 | import com.joshlong.rsocket.client.qualifiers.Constants; 5 | import org.springframework.beans.factory.annotation.Qualifier; 6 | import org.springframework.messaging.handler.annotation.MessageMapping; 7 | import reactor.core.publisher.Mono; 8 | 9 | @RSocketClient 10 | @Qualifier(Constants.QUALIFIER_2) 11 | public interface GreetingClient { 12 | 13 | @MessageMapping("greetings-with-name") 14 | Mono greetMono(Mono name); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/qualifiers/greetings/GreetingsController.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.qualifiers.greetings; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.springframework.context.annotation.Profile; 5 | import org.springframework.messaging.handler.annotation.MessageMapping; 6 | import org.springframework.stereotype.Controller; 7 | import reactor.core.publisher.Mono; 8 | 9 | import javax.annotation.PostConstruct; 10 | 11 | @Log4j2 12 | @Profile("service") 13 | @Controller 14 | public class GreetingsController { 15 | 16 | @PostConstruct 17 | public void go() { 18 | log.info(getClass().getName()); 19 | } 20 | 21 | @MessageMapping("greetings-with-name") 22 | Mono greetMono(Mono name) { 23 | return name.map(Greeting::new); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/qualifiers/people/Person.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.qualifiers.people; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | class Person { 11 | 12 | private String name; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/qualifiers/people/PersonClient.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.qualifiers.people; 2 | 3 | import com.joshlong.rsocket.client.RSocketClient; 4 | import com.joshlong.rsocket.client.qualifiers.Constants; 5 | import org.springframework.beans.factory.annotation.Qualifier; 6 | import org.springframework.messaging.handler.annotation.MessageMapping; 7 | import reactor.core.publisher.Flux; 8 | 9 | @RSocketClient 10 | @Qualifier(Constants.QUALIFIER_1) 11 | public interface PersonClient { 12 | 13 | @MessageMapping("people") 14 | Flux people(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/qualifiers/people/PersonController.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.qualifiers.people; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.springframework.context.annotation.Profile; 5 | import org.springframework.messaging.handler.annotation.MessageMapping; 6 | import org.springframework.stereotype.Controller; 7 | import reactor.core.publisher.Flux; 8 | 9 | import javax.annotation.PostConstruct; 10 | 11 | @Log4j2 12 | @Profile("service") 13 | @Controller 14 | public class PersonController { 15 | 16 | @PostConstruct 17 | public void go() { 18 | log.info(getClass().getName()); 19 | } 20 | 21 | @MessageMapping("people") 22 | Flux people() { 23 | return Flux.just(new Person("Yuxin"), new Person("Jane"), new Person("John"), new Person("Sergei")); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/simple/GreetingClient.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.simple; 2 | 3 | import com.joshlong.rsocket.client.RSocketClient; 4 | import org.springframework.messaging.handler.annotation.DestinationVariable; 5 | import org.springframework.messaging.handler.annotation.MessageMapping; 6 | import org.springframework.messaging.handler.annotation.Payload; 7 | import reactor.core.publisher.Flux; 8 | import reactor.core.publisher.Mono; 9 | 10 | @RSocketClient 11 | interface GreetingClient { 12 | 13 | @MessageMapping("greetings") 14 | Mono greet(); 15 | 16 | @MessageMapping("greetings-with-channel") 17 | Flux greetParams(Flux names); 18 | 19 | @MessageMapping("greetings-stream") 20 | Flux greetStream(Mono name); 21 | 22 | @MessageMapping("greetings-with-name") 23 | Mono greet(Mono name); 24 | 25 | @MessageMapping("fire-and-forget") 26 | Mono greetFireAndForget(Mono name); 27 | 28 | @MessageMapping("greetings-mono-name.{name}.{age}") 29 | Mono greetMonoNameDestinationVariable(@DestinationVariable("name") String name, 30 | @DestinationVariable("age") int age, @Payload Mono payload); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/simple/GreetingResponse.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.simple; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class GreetingResponse { 11 | 12 | private String message; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/simple/GreetingsController.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.simple; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.springframework.context.annotation.Profile; 5 | import org.springframework.messaging.handler.annotation.DestinationVariable; 6 | import org.springframework.messaging.handler.annotation.MessageMapping; 7 | import org.springframework.messaging.handler.annotation.Payload; 8 | import org.springframework.stereotype.Controller; 9 | import reactor.core.publisher.Flux; 10 | import reactor.core.publisher.Mono; 11 | 12 | import javax.annotation.PostConstruct; 13 | import java.util.concurrent.atomic.AtomicReference; 14 | import java.util.stream.Stream; 15 | 16 | @Log4j2 17 | @Profile("service") 18 | @Controller 19 | class GreetingsController { 20 | 21 | static AtomicReference fireAndForget = new AtomicReference<>(); 22 | 23 | @PostConstruct 24 | public void begin() { 25 | log.info("begin()"); 26 | } 27 | 28 | @MessageMapping("greetings-mono-name.{name}.{age}") 29 | Mono greetMonoNameDestinationVariable(@DestinationVariable("name") String name, 30 | @DestinationVariable("age") int age, @Payload Mono payload) { 31 | log.info("name=" + name); 32 | log.info("age=" + age); 33 | return payload; 34 | } 35 | 36 | @MessageMapping("fire-and-forget") 37 | Mono fireAndForget(Mono valueIn) { 38 | return valueIn// 39 | .doOnNext(value -> { 40 | log.info("received fire-and-forget " + value + '.'); 41 | fireAndForget.set(value); 42 | })// 43 | .then(); 44 | } 45 | 46 | @MessageMapping("greetings-with-channel") 47 | Flux greetParams(Flux names) { 48 | return names.map(String::toUpperCase).map(GreetingResponse::new); 49 | } 50 | 51 | @MessageMapping("greetings-stream") 52 | Flux greetFlux(Mono name) { 53 | return name.flatMapMany( 54 | leNom -> Flux.fromStream(Stream.generate(() -> new GreetingResponse(leNom.toUpperCase()))).take(2)); 55 | } 56 | 57 | @MessageMapping("greetings-with-name") 58 | Mono greetMono(Mono name) { 59 | return name.map(GreetingResponse::new); 60 | } 61 | 62 | @MessageMapping("greetings") 63 | Mono greet() { 64 | log.info("invoking greetings and returning a GreetingsResponse."); 65 | return Mono.just(new GreetingResponse("Hello, world!")); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/simple/RSocketClientConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.simple; 2 | 3 | import com.joshlong.rsocket.client.EnableRSocketClients; 4 | import lombok.extern.log4j.Log4j2; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Profile; 9 | import org.springframework.messaging.rsocket.RSocketRequester; 10 | 11 | import javax.annotation.PostConstruct; 12 | 13 | @Log4j2 14 | @Profile("client") 15 | @EnableRSocketClients 16 | @SpringBootApplication 17 | class RSocketClientConfiguration { 18 | 19 | @PostConstruct 20 | public void start() { 21 | log.info("starting " + RSocketClientConfiguration.class.getName() + '.'); 22 | } 23 | 24 | @Bean 25 | RSocketRequester rSocketRequester(@Value("${service.port}") int port, RSocketRequester.Builder builder) { 26 | return builder.connectTcp("localhost", port).block(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/simple/RSocketClientTest.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.simple; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.junit.jupiter.api.AfterAll; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.BeforeAll; 7 | import org.junit.jupiter.api.Test; 8 | import org.springframework.boot.WebApplicationType; 9 | import org.springframework.boot.builder.SpringApplicationBuilder; 10 | import org.springframework.context.ConfigurableApplicationContext; 11 | import org.springframework.util.SocketUtils; 12 | import reactor.core.publisher.Flux; 13 | import reactor.core.publisher.Mono; 14 | import reactor.test.StepVerifier; 15 | 16 | import java.util.concurrent.atomic.AtomicInteger; 17 | 18 | @Log4j2 19 | public class RSocketClientTest { 20 | 21 | static ConfigurableApplicationContext serviceApplicationContext; 22 | 23 | static AtomicInteger port = new AtomicInteger(SocketUtils.findAvailableTcpPort()); 24 | 25 | @BeforeAll 26 | public static void begin() { 27 | serviceApplicationContext = new SpringApplicationBuilder(RSocketServerConfiguration.class)// 28 | .web(WebApplicationType.NONE) 29 | .run("--spring.profiles.active=service", "--spring.rsocket.server.port=" + port.get()); 30 | } 31 | 32 | @AfterAll 33 | public static void destroy() { 34 | serviceApplicationContext.stop(); 35 | } 36 | 37 | @Test 38 | public void destinationVariablesAndPayload() { 39 | GreetingClient greetingClient = buildClient(); 40 | Mono greetingResponseFlux = greetingClient.greetMonoNameDestinationVariable("jlong", 36, 41 | Mono.just("Hello")); 42 | StepVerifier// 43 | .create(greetingResponseFlux)// 44 | .expectNextMatches(gr -> gr.equalsIgnoreCase("Hello"))// 45 | .verifyComplete(); 46 | } 47 | 48 | @Test 49 | public void monoInFluxOut() { 50 | GreetingClient greetingClient = buildClient(); 51 | Flux greetingResponseFlux = greetingClient.greetStream(Mono.just("a")); 52 | StepVerifier// 53 | .create(greetingResponseFlux)// 54 | .expectNextCount(1).expectNextMatches(gr -> gr.getMessage().equalsIgnoreCase("A"))// 55 | .verifyComplete(); 56 | 57 | } 58 | 59 | @Test 60 | public void fluxInFluxOut() { 61 | GreetingClient greetingClient = buildClient(); 62 | Flux greetingResponseFlux = greetingClient.greetParams(Flux.just("a", "b")); 63 | StepVerifier// 64 | .create(greetingResponseFlux)// 65 | .expectNextMatches(gr -> gr.getMessage().equalsIgnoreCase("A"))// 66 | .expectNextMatches(gr -> gr.getMessage().equalsIgnoreCase("B"))// 67 | .verifyComplete(); 68 | 69 | } 70 | 71 | @Test 72 | public void monoInMonoOut() { 73 | GreetingClient greetingClient = buildClient(); 74 | Mono greet = greetingClient.greet(Mono.just("Hello, Mario")); 75 | StepVerifier// 76 | .create(greet)// 77 | .expectNextMatches(gr -> gr.getMessage().equalsIgnoreCase("Hello, Mario"))// 78 | .verifyComplete(); 79 | 80 | } 81 | 82 | @Test 83 | public void noValueInMonoOut() throws Exception { 84 | GreetingClient greetingClient = buildClient(); 85 | Mono greet = greetingClient.greet(); 86 | StepVerifier// 87 | .create(greet)// 88 | .expectNextMatches(gr -> gr.getMessage().equalsIgnoreCase("Hello, world!"))// 89 | .verifyComplete(); 90 | 91 | } 92 | 93 | @Test 94 | public void fireAndForget() throws Exception { 95 | GreetingClient greetingClient = buildClient(); 96 | String name = "Kimly"; 97 | Mono greet = greetingClient.greetFireAndForget(Mono.just(name)); 98 | StepVerifier// 99 | .create(greet)// 100 | .verifyComplete(); 101 | 102 | Thread.sleep(1000); 103 | boolean kimly = GreetingsController.fireAndForget.get().equalsIgnoreCase(name); 104 | Assertions.assertTrue(kimly, "the name perceived on the service is the same as we sent."); 105 | } 106 | 107 | private GreetingClient buildClient() { 108 | ConfigurableApplicationContext context = new SpringApplicationBuilder(RSocketClientConfiguration.class)// 109 | .web(WebApplicationType.NONE)// 110 | .run("--service.port=" + port.get(), "--spring.profiles.active=client"); 111 | return context.getBean(GreetingClient.class); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /rsocket-client/src/test/java/com/joshlong/rsocket/client/simple/RSocketServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.joshlong.rsocket.client.simple; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.context.annotation.Profile; 8 | 9 | import javax.annotation.PostConstruct; 10 | 11 | @Log4j2 12 | @Profile("service") 13 | @Configuration 14 | @EnableAutoConfiguration 15 | class RSocketServerConfiguration { 16 | 17 | @Bean 18 | GreetingsController greetingsController() { 19 | return new GreetingsController(); 20 | } 21 | 22 | @PostConstruct 23 | public void start() { 24 | log.info("starting " + RSocketServerConfiguration.class.getName() + '.'); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /rsocket-client/src/test/resources/application-service.properties: -------------------------------------------------------------------------------- 1 | spring.rsocket.server.port=8888 -------------------------------------------------------------------------------- /rsocket-client/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.com.joshlong.rsocket.client=DEBUG -------------------------------------------------------------------------------- /samples/hello/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /samples/hello/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.6"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /samples/hello/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshlong-attic/a-feign-like-rsocket-client/97dd1dfa5c89379105b4853fa2f0abe041d9692a/samples/hello/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /samples/hello/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /samples/hello/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /samples/hello/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /samples/hello/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.3.1.RELEASE 9 | 10 | 11 | com.example 12 | test 13 | 0.0.1-SNAPSHOT 14 | test 15 | Demo project for Spring Boot 16 | 17 | 18 | 11 19 | 20 | 21 | 22 | 23 | com.joshlong.rsocket 24 | client 25 | 0.0.1-SNAPSHOT 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-rsocket 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | org.junit.vintage 39 | junit-vintage-engine 40 | 41 | 42 | 43 | 44 | io.projectreactor 45 | reactor-test 46 | test 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-maven-plugin 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /samples/hello/src/main/java/com/example/test/client/TestApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.test.client; 2 | 3 | import com.joshlong.rsocket.client.EnableRSocketClients; 4 | import com.joshlong.rsocket.client.RSocketClient; 5 | import lombok.RequiredArgsConstructor; 6 | import lombok.SneakyThrows; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.context.event.ApplicationReadyEvent; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.context.event.EventListener; 13 | import org.springframework.messaging.handler.annotation.MessageMapping; 14 | import org.springframework.messaging.rsocket.RSocketRequester; 15 | import org.springframework.stereotype.Component; 16 | import reactor.core.publisher.Mono; 17 | 18 | @EnableRSocketClients 19 | @SpringBootApplication 20 | public class TestApplication { 21 | 22 | @Bean 23 | RSocketRequester rSocketRequester(RSocketRequester.Builder builder) { 24 | return builder.connectTcp("localhost", 8888).block(); 25 | } 26 | 27 | @SneakyThrows 28 | public static void main(String[] args) { 29 | SpringApplication.run(TestApplication.class, args); 30 | System.in.read(); 31 | } 32 | 33 | } 34 | 35 | @Component 36 | @RequiredArgsConstructor 37 | class Client { 38 | 39 | private final GreetingsClient client; 40 | 41 | @EventListener(ApplicationReadyEvent.class) 42 | public void ready() { 43 | Mono world = this.client.hello(Mono.just("World")); 44 | world.subscribe(System.out::println); 45 | 46 | } 47 | } 48 | 49 | @RSocketClient 50 | interface GreetingsClient { 51 | 52 | @MessageMapping("hello") 53 | Mono hello(Mono name); 54 | } -------------------------------------------------------------------------------- /samples/hello/src/main/java/com/example/test/service/TestApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.test.service; 2 | 3 | import lombok.extern.log4j.Log4j2; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Profile; 7 | import org.springframework.messaging.handler.annotation.MessageMapping; 8 | import org.springframework.stereotype.Controller; 9 | 10 | import javax.annotation.PostConstruct; 11 | 12 | @SpringBootApplication 13 | public class TestApplication { 14 | 15 | public static void main(String[] args) { 16 | System.setProperty("spring.profiles.active", "service"); 17 | System.setProperty("spring.rsocket.server.port", "8888"); 18 | SpringApplication.run(TestApplication.class, args); 19 | } 20 | 21 | } 22 | 23 | 24 | @Controller 25 | @Log4j2 26 | class GreetingsController { 27 | 28 | @PostConstruct 29 | public void construct() { 30 | log.info("construct()"); 31 | } 32 | 33 | @MessageMapping("hello") 34 | String hello(String name) { 35 | return "Hello, " + name + "!"; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /samples/hello/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshlong-attic/a-feign-like-rsocket-client/97dd1dfa5c89379105b4853fa2f0abe041d9692a/samples/hello/src/main/resources/application.properties -------------------------------------------------------------------------------- /samples/hello/src/test/java/com/example/test/TestApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.test; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TestApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------