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

Blog    

Recommend

How will the three major operators fight in 2022?

2022 is here. In this new year, how will the thre...

Why is CDN designed this way?

Over the past few decades, computer networks have...

Passive Wi-Fi technology bridges the digital divide

The digital divide is a term used to describe the...

Cybersecurity risks of smart devices

Many people don’t consider the risks that smart d...

WIFi 5 Final Madness 2019 Wireless Router Market Report

In 2019, the wireless router market faced the fie...

Domestic IPv6 system deployment speeds up and IPv6 application boom is coming

The current Internet Protocol address IPv4 addres...

Network upgrades you should consider in 2021

As 2020 winds down and the new year dawns, it pro...

Network virtualization market development status in 2022

Network virtualization software allows companies ...

New wireless technology extends 5G value proposition indoors

Since most 5G networks are deployed using the 3.5...

Microsoft drops OneDrive sync support for older versions of macOS

On August 8, Microsoft announced that they will d...