Dubbo for distributed services

1、 Dubbo introduction

Dubbo is a high-performance, lightweight open source Java service framework.

It provides six core capabilities: interface agent oriented high-performance RPC call, intelligent fault tolerance and load balancing, automatic service registration and discovery, highly scalable capability, runtime traffic scheduling, visual service governance and operation and maintenance.

Main functions of Dubbo

2、 Dubbo technical principle

Overall architecture diagram:

Application of SPI

SPI and API

Serviceloader mechanism

Meta inf / Dubbo / interface fully qualified name, and the file content is the implementation class

Two other similar mechanisms: callback and eventbus

How are services exposed

How to reference a service

Clustering and routing

Generalized reference

Genericservice when we know the interfaces, methods and parameters, we can use reflection to call the service.

Method 1:

<dubbo:reference id="barService" interface="com.foo.BarService" generic="true" /> GenericService barService = (GenericService) applicationContext.getBean("barService"); Object result = barService.$invoke("sayHello",new String[] { "java.lang.String" },new Object[] { "World" });

Method 2:

ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
reference.setInterface("com.xxx.XxxService");
reference.setVersion("1.0.0"); 
reference.setGeneric(true);
GenericService genericService = reference.get();

Implicit parameter context mode

RpcContext. getContext(). setAttachment("index","1");

This parameter can be propagated throughout the RPC call

Mock

Set mock to true and implement a corresponding mock implementation class. For example, the mock class of helloservice is helloservicemock

3、 Dubbo best practices

Development subcontracting

Environmental isolation and grouping

How to achieve multi environment isolation?

Parameter configuration

The general parameters are subject to the consumer end. If the consumer end is not set, the provider value is used

The recommended consumer attributes configured on the provider side are:

The recommended provider side properties configured on the provider side are:

Container deployment

Registered IP problem, solution:

O & M and monitoring

Admin has simple functions and can integrate the monitoring system of your own company:

Retry and idempotent

If the service call fails, it will retry by default, so the interface needs idempotency

Design idempotent interface method:

4、 Source code analysis

Look at it with questions

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>