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 future technologies will improve physical security in data centers

In recent years, the demand for security solution...

RAKsmart: $59/month-2*E5-2620v2/32GB/1TB/50M bandwidth/South Korea server

Thanks to the advantage of physical distance, mos...

5G network speed has shrunk? Q3 saw a year-on-year decline of up to 39%

Recently, Ookla, a network connection speed testi...

Don't waste money and choose the router that suits you best

Nowadays, remote video conferencing and online cl...

Three tips for data center network maintenance

The network is the most important component of th...

HostDare: 25% off NVMe VPS in Los Angeles starting at $19.5/year

I received the latest promotional email from Host...

What the future of wide area network (WAN) management looks like

The recent surge in the number of employees worki...

Omdia Observation: TIP open core network plan is progressing slowly

According to the latest report from market resear...

Let's talk about network equipment

My home was recently renovated. As a computer pro...