dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

[issue465_1054_2043]Issue Conclusion

Open lamianer opened this issue 8 years ago • 3 comments

Issue 1:xml configuration for shutdown

1、Basic concepts

Graceful Shutdown

Dubbo's native support for graceful downtime is based on the configured file named “dubbo.properties”. We added the value as follows:

Dubbo.service.shutdown.wait=XX

that is to say, Dubbo stops receiving tasks, and waits for the completion of existing tasks, waiting for XX milleseconds.

Configuration

  1. Properties Configuration "dubbo.properties": it stores the configuration information shared by multiple containers and acts as a micro-registration center. It initialize the configuration through jvm.
  2. Xml configuration: we use the .xml to decouples the configuration of each component of dubbo. And bind with individual own configuration class and configuration tag, which is more friendly to the system development. See more details:

Http://dubbo.apache.org/en/us/docs/user/references/xml/introduction.html

2. Solution

We configure the timeout for graceful shutdown in the xml file. For the tag named dubbo:registry, there is a parameter “wait”, image

which denoted the timeout.

3. Implementation

image

Add a wait tag in the provider.xml.

4. Result

image image

Issue 2: expose application for provider

Problems

It is difficult for provider side to quickly locate which consumer's request has a problem. Thus the Dubbo needs to support application name in the url for better development experience.

Solution

  1. Consumer We define the application name in the “consumer.xml” image

  2. RpcContext
    

RpcContext is a java class, defining a lot of parameters passed between the provider and consumer during the Remote Procedure Call. Thus we need to expand RpcContext.java to send the application name. 3) ConsumerContextFilter Before the consumer calls the remote service, we first call the invoke() method of the ConsumerContextFilter. And the method initializes the values of the RPC context information including the application name. 4) Provider The service provider can get the application name from the RpcContext.

Implementation

Solution 1.

We tried two solutions when solving this problem. The first one is to add a new field “applicationName” to support the application name and two methods: setapplicationName() and getapplicationName() in RpcContext class. Then we add RpcContext. setapplicationName() in the invoke() of ComsumerContextFilter class. But when we use the getapplicationName() method to get the application information in the provider side, the value appears null. The protocol does not support the extension.

Solution 2.

After careful review, it is found that there is an attachments field in the RpcContext, which supports the developer to extend the field value in the form of a key-value. Details can be seen as follows: First, in the ConsumerContextFilter, we add the setAttachment() in invoke() method. The key is "Constants.APPLICATION_KEY" and the value can be extracted from the url.

image

Result

image image

Issue 3: support register host

Dubbo has supported Providers to register their host to the registry server, and registry server can automatically get the IP by host name.
Firstly:configure the host name of provider in the xml configuration file, the configuration is:
image

Secondly: In the ContextFilter, we add the NetUtil.getIpByHost method to map the host to Ip. You could try like this.

image

Result

image

lamianer avatar Aug 28 '18 13:08 lamianer

@lamianer You can send pull request?

ningyu1 avatar Sep 03 '18 08:09 ningyu1

Hi, @lamianer It is recommended that you send an email to discuss the correctness of the conclusion. Close the current issue and reopen when there are other issues

carryxyh avatar Sep 11 '18 03:09 carryxyh

FYI

https://lists.apache.org/thread.html/995957313e29ca5173ddda727a031d09dd018e1a4119d203bfc560e4@%3Cdev.dubbo.apache.org%3E

diecui1202 avatar Sep 11 '18 03:09 diecui1202