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

How to prevent 5G from creating a new digital divide

There is no doubt that more pervasive 5G technolo...

What you need to know about Wi-Fi 7

As Wi-Fi 7 continues to make waves in the technol...

Sparks from blockchain and the Internet of Things

The Internet of Things is the application that is...

Why is distributed networking an emerging trend?

The mass adoption of the Internet can be attribut...

Blockchain makes cities smarter and more innovative

This article takes stock of the smart city applic...

How can operators play the 5G messaging card well?

5G is a technology that can rewrite the "rul...

How many HTTP requests can you guess on a TCP connection?

A classic interview question is what happens from...

Seven key developments for SD-branch in 2020

In the next few years, the connection of remote b...

Cisco fully opens a new era of smart office

Technology has revolutionized the human work expe...

If the TCP protocol is used, will there be no packet loss?

Data packet sending process First, the green chat...