The features of dubbo are different from those of spring cloud

Dubbo supports the service provision mode of short connection and large amount of data, but in most cases, it uses the mode of long connection and small amount of data to provide services. Therefore, Dubbo is indeed an option that can be considered for products with many synchronous call scenarios like e-commerce and can support the cost of building Dubbo, a complex environment. However, if there are more asynchronous logic in the product business due to the complexity and long time of background business logic, Dubbo may not be appropriate. At the same time, for start-ups with insufficient manpower, it is not very convenient to maintain such a heavy architecture.

Spring Cloud is composed of many sub projects, such as Spring Cloud Config, Spring Cloud Netflix, Spring Cloud consult, etc. it provides common tools for building distributed systems and micro services, such as configuration management, service discovery, circuit breaker, intelligent routing, micro agent, control bus, one-time token, global lock, master selection, distributed session and cluster status, It meets all the solutions needed to build microservices. For example, Spring Cloud Config can be used to implement a unified configuration center for unified configuration management; Using Spring Cloud Netflix, you can realize the functions of Netflix components - Service Discovery (Eureka), intelligent routing (Zuul), and client load balancing (Ribbon).

Characteristics of dubbo

Although there are no recognized technical standards, specifications or drafts for microservice architecture, there are already some influential open-source microservice Architecture Frameworks in the industry that provide key ideas for microservices, such as Dubbo and Spring Cloud.
Major Internet companies also have self-developed micro service frameworks, but their models are not different from the two.

The interface proxy oriented high-performance RPC call provides high-performance proxy based remote call capability. The service takes the interface as the granularity and shields the underlying details of remote call for developers.
Intelligent load balancing has built-in multiple load balancing strategies to intelligently sense the health status of downstream nodes, significantly reduce call delay and improve system throughput.

Automatic service registration and discovery supports a variety of registry services, and service instances can be perceived online and offline in real time.
Highly scalable capabilities follow the design principle of microkernel + plug-in. All core capabilities such as Protocol, Transport and Serialization are designed as extension points, and built-in implementations and third-party implementations are treated equally.
Routing strategies such as built-in conditions and scripts for traffic scheduling during operation can easily realize gray publishing and priority in the same computer room by configuring different routing rules.

Visual service governance and operation and maintenance provide rich service governance and operation and maintenance tools: query service metadata, service health status and call statistics at any time, issue routing strategies and adjust configuration parameters in real time.

Core of microservices

The core elements of microservices are service discovery, registration, routing, fusing, degradation and distributed configuration

Overall architecture of Dubbo

Provider: the provider that exposes the service. You can start the service through jar or container
Consumer: the service consumer that invokes the remote service
Registry: service registry and Discovery Center
Monitor: count the service and call times, and call the time monitoring center
Container: the container where the service runs

Overall architecture of Spring Cloud

Service Provider exposes the provider of the service
Service Consumer the Service Consumer that calls the remote service
EureKa Server service registry and service discovery center

Demo case Dubbo

Server

Define a Service Interface: (HelloService.java)

public interface HelloService{

  String sayHello(String name);

}

Implementation class of interface: (HelloServiceImpl.java)

public  class  HelloServiceImpl  implements  HelloService{
    public  String  sayHello(String  name){
        return  "Hello" + name;
    }
}

Spring configuration: (provider.xml)

<?xmlversion="1.0"encoding="UTF-8"?>
<beans......>
    <!--Applicationname-->
    <dubbo:applicationname="hello-world-app"/>
    <!--registryaddress,usedforservicetoregisteritself-->
    <dubbo:registryaddress="multicast://224.5.6.7:1234"/>
    <!--exposethisservicethroughdubboprotocol,throughport20880-->
    <dubbo:protocolname="dubbo"port="20880"/>
    <!--whichserviceinterfacedoweexpose?-->
    <dubbo:serviceinterface="com.xxx.HelloService"ref="helloService"/>
    <!--designateimplementation-->
    <beanid="helloService"class="com.xxx.impl.HelloServiceImpl"/>
</beans>

Test code: (Provider.java)

public  class  Provider{
    public  static  void  main(String[]  args){
        ClassPathXmlApplicationContext  context = new  ClassPathXmlApplicationContext(newString[]{"provider.xml"});
        //Start successfully. The listening port is 20880system in. read();// press any key to exit
    }
}

client

Spring configuration file: (consumer.xml)

<?xmlversion="1.0"encoding="UTF-8"?>
<beans xmlns=......>
    <!--consumerapplicationname-->
    <dubbo:applicationname="consumer-of-helloworld-app"/>
    <!--registryaddress,usedforconsumertodiscoverservices-->
    <dubbo:registryaddress="multicast://224.5.6.7:1234"/>
    <!--whichservicetoconsume?-->
    <dubbo:referenceid="helloService"interface="com.xxx.HelloService"/>
</beans>

Client test code: (Consumer.java)

public  class  Consumer{
    public  static  void  main(String[]  args){
        ClassPathXmlApplicationContext  context = new  ClassPathXmlApplicationContext(newString[]{"consumer.xml"});
        HelloService  helloService = (HelloService)context.getBean("helloService");
        //getserviceinvocationproxyStringhello=helloService.sayHello("world");
        //doinvoke!System.out.println(hello);
        //cool,howareyou~
    }
}

Keywords: Back-end Spring Cloud Cloud Native

Added by dearsina on Fri, 04 Feb 2022 10:41:46 +0200