Dubbo 3.0? No! RSocket is the eternal god

Dubbo 3.0? No! RSocket is the eternal god

[[411111]]

background

The hottest topic in the domestic technology circle recently is the release of Apache Dubbo 3.0. The most important feature of Dubbo 3 is the combination of HTTP/2 as the underlying communication protocol and protobuf as the serialization protocol. This combination is also the solution used by the gRPC protocol. In the end, the RSocket protocol was not selected as a supplementary solution for reactive programming.

Dubbo 3.0 source code examples

  • RSocket is a new, language-independent, layer 7 application network protocol. It is a bidirectional, multiplexed, message-based, reactive stream backpressure-based binary protocol. Different from the traditional network programming model HTTP Request/Response method. In addition to the Request/Response method, RSocket also supports Fire And Forget (send without return), Stream (unidirectional flow), and Channel (bidirectional flow).
  • For the basics of RSocket, please refer to the author's article "RSocket | The only alternative to REST".
  • This article focuses on the use of spring-retrosocket, a new project in Spring's official incubator.

Spring Incubator Screenshot

spring-retrosocket provides an annotation-driven RSocket client and shields the complexity of rosocket-java sdk through annotation calls.

1.   Create RSocket Server

Create a spring boot project and add relevant dependencies

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-rsocket</artifactId>
  4. </dependency>

Just specify the rsocket server service port

  1. spring.rsocket.server.port=8848

Define RR request model processing channel

Use @MessageMapping to specify the routing path

  1. @Controller
  2. public class GreetingsController {
  3. @MessageMapping( "request-response" )
  4. Mono<String> reqResponse(@Payload String payload) {
  5. log.info( "Received RR request information: {}" , payload);
  6. return Mono.just( "Hello, " + payload);
  7. }
  8. }

2. Create a client using spring-retrosocket

  • Use the Spring Initializr and generate a new project.
rely Version
spring-retrosocke 0.0.1-SNAPSHOT
Spring Boot 2.5.2
  1. <dependency>
  2. <groupId>org.springframework.retrosocket</groupId>
  3. <artifactId>spring-retrosocket</artifactId>
  4. <version>0.0.1-SNAPSHOT</version>
  5. </dependency>
  • Add spring maven repository

If you have an existing build, make sure you have the spring-milestones or spring-snapshots Spring repository.

  1. <repositories>
  2. <repository>
  3. <id>spring-milestones</id>
  4. < name >Spring Milestones</ name >
  5. <url>https://repo.spring.io/milestone</url>
  6. </repository>
  7. <repository>
  8. <id>spring-snapshots</id>
  9. < name >Spring Snapshots</ name >
  10. <url>https://repo.spring.io/snapshot</url>
  11. <snapshots>
  12. <enabled> true </enabled>
  13. </snapshots>
  14. </repository>
  15. </repositories>

3. Basic usage

  • Enable RSocket client support In your Java code, you need to enable RSocket client support. Use the @EnableRSocketClient annotation. You also need to define a RSocketRequester bean.
  1. @SpringBootApplication
  2. @EnableRSocketClients
  3. class RSocketClientApplication {
  4. @Bean
  5. RSocketRequester requester(RSocketRequester.Builder builder) {
  6. return builder.connectTcp( "localhost" , 8888).block();
  7. }
  8. }
  • Then, define an RSocket client interface (similar to FeignClient) as follows:
  1. @RSocketClient
  2. interface GreetingClient {
  3. @MessageMapping( "request-response" )
  4. Mono<GreetingResponse> requestResponse(Mono<String> name );
  5. }
  • Test code
  1. @SpringBootTest
  2. class DemoApplicationTests {
  3.  
  4. @Autowired
  5. private GreetingClient greetingClient;
  6.  
  7. @Test
  8. void testGreetingClient() {
  9. Mono<String> stringMono = greetingClient.requestResponse(Mono.just( "lengleng" ));
  10. System. out .println(stringMono.block());
  11. }
  12. }

spring-retrosocket github source code: https://github.com/spring-projects-experimental/spring-retrosocket

<<:  my country's backbone network construction will be initially completed in 2020

>>:  An article to help you understand the concept of TCP/IP

Recommend

5G: Number of terminal connections exceeds 200 million

2020 is the first year of large-scale constructio...

What is CDN? A detailed explanation of CDN in one article

[[254871]] In today's mobile Internet era, mo...

5G+AR ushering in a new "blue ocean"

[[408334]] In recent years, the development of te...

RackNerd adds new Seattle data center, 1GB memory package costs $11.95 per year

In the middle of last month, we shared the news t...

What does a 5G base station look like? What is the difference between it and 4G?

This is what ordinary people think of 4G and 5G b...