Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to open the Dubbo framework without repeating the available port function

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to open the Dubbo framework without repeating the available port function". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to open the Dubbo framework without repeating the available port function.

Business scenario

Currently, we basically deploy one application per server, so the port of the dubbo protocol is configured in advance. For example, the dubbo protocol uses 20880, and the rest protocol uses 20889. However, if you need to deploy multiple instance nodes on the same server, port conflicts may occur, and there are two solutions:

Assign and modify the port manually; (obviously not elegant, and the cost of late operation and maintenance is very high)

The system supports automatic port allocation; (preferred scheme)

This article is through the dubbo source code interpretation, explain how to configure to achieve the second scheme.

Open the auto-assign port

Configured here with dubbo.xml in dubbox

If port is left empty or directly set to null, the system default port will be used; if set to less than 0 (for example,-1), unused ports will be randomly assigned.

The dubbo protocol starts from 20880, and the rest protocol starts from port 80.

Old version of dubbo framework source code

Method source code: com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol ()

This method is called when the dubbo container is started and provider export is initialized, including the IP address and the logic of port acquisition. The following is the source code for port processing:

/ / read the port configuration Integer port = protocolConfig.getPort () from the dubbo:protocol tag; / / if there is a provider tag configuration and the port in the protocol is configured as null or 0, then directly use the port port if in provider (provider! = null & & (port = = null | | port = = 0)) {port = provider.getPort () } / / obtain the default port number according to the protocol type (dubbo protocol port is 20880, the source code is described below) final int defaultPort = ExtensionLoader.getExtensionLoader (Protocol.class) .getExtension (name). GetDefaultPort (); / / if port is configured as null or 0, the default port if (port = = null | | port = = 0) {port = defaultPort will be used } / / if port is null after default port processing (for example, no default port is configured in the protocol) or a negative number, a port if is randomly generated (port = = null | | port java system properties-> port property in protocol config file *-> protocol default port * * @ param name * @ return * / private Integer findConfigedPorts (ProtocolConfig protocolConfig, String name, Map map) {Integer portToBind = null / / support getting the port from the environment variable / / parse bind port from environment String port = getValueFromConfig (protocolConfig, DUBBO_PORT_TO_BIND); portToBind = parsePort (port); / / if the environment variable does not configure the binding port, go to the following logic / / if there's no bind port found from environment, keep looking up. If (portToBind = = null) {/ /

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report