In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the "how to upgrade the version of dubbo2.7.4.1 smooth migration to the registry nacos" related knowledge, editor through the actual case to show you the process of operation, the method of operation is simple and fast, practical, I hope that this "how to upgrade the version of dubbo2.7.4.1 smooth migration to the registry nacos" article can help you solve the problem.
Preface
Dubbo is a very excellent service governance RPC framework. The advantage of dubbo lies in its huge architecture, exquisite module design, flexible SPI design and rich component implementation. When bloggers made micro-service technology selection to inspect dubbo, they were amazed that others had been able to produce such excellent projects at that time, so that whenever someone said they wanted to learn architecture design, I would recommend them to read dubbo code. Learn the architectural design principles of dubbo. It is often said that dubbo is not only a RPC framework, because its service governance feature is more prominent than RPC communications. This feature led me to choose him decisively in 2017, when dubbo officially did not produce spring boot starter, and most of our projects completed the transformation from spring mvc to spring boot projects. In order to simplify the development of integrated dubbo components, we developed a set of spring-boot-dubbo-starter components based on the dubbo2.5.6 version, and customized the dubbo service exposure and introduced annotations, and customized the configuration loading mode of dubbo. At that time, there was no professional operation and maintenance, and it also cost resources to build a highly available zk. In order to simplify and facilitate the maintenance of a component, we directly chose redis (Aliyun high availability instance) as the registry center of dubbo. The above is the background of our upgrade of dubbo.
Why upgrade to 2.7.4.1?
From 2.5.6 to 2.7.x, there are a lot of bug fixes in the middle, bringing a lot of new features.
Version 2.5.x is no longer a reserved maintenance version, currently the main maintenance is 2.6.x and 2.7.x, as well as exploration version 3.0. In other words, even if there is a problem after 2.5.x, the authorities will not fix it.
The reason for choosing version 2.7.4.1 is that after studying the official issue and following the situation in the dubbo group, it is found that this version is relatively stable, and it is also recommended to upgrade to this version.
Why migrate the registry to nacos?
At present, although the redis registry has gone through a pit, "a series of problems in the use of the redis registry by dubbo" tends to be stable, but many problems have not been exposed due to too few people and too few users (another problem with the redis registry was found in the process of upgrading). If you continue to use the redis registry, you will be unable to extricate yourself from the process of constantly wading through the pit.
Nacos is a registry project officially promoted by dubbo. Although it is still running-in iteratively, the official response is relatively timely once a problem is found. More and more people use nacos, which is equivalent to going to the pit, so there is no place to hide the hidden bug. Moreover, nacos and dubbo are born by blood. Looking at the recent release situation of nacos, we found that there are several problems that have been specially repaired for dubbo registration.
Nacos has its own web management console, which can easily query the registration of dubbo, and can be used as a simple dubbo governance center.
Two upgrade schemes
Since we currently maintain our own spring-boot-dubbo-starter, we have produced two different upgrade schemes, both of which have been fully verified when we do the upgrade.
Plan 1: change the official starter component by magic
In order to upgrade to version 2.7.4.1 without awareness on the development side, we did two things
Annotation compatibility
Two options have also been considered when doing annotation compatibility, one is compatible with dubbo2.7.4.1 on the self-developed starter, and the other is compatible with our processing on the official 2.7.4.1 starter. The latter was chosen decisively, because the dubbo2.7.4.1 version is a black box for us. We don't know what changes there are. Forward compatibility is more difficult, but reverse compatibility is much easier. We completely copied the custom annotations from the original self-developed components to the official starter project, and then removed ReferenceAnnotationBeanPostProcessor and ServiceAnnotationBeanPostProcessor from the spring module of dubbo to deal with custom annotations. This place once again exaggerates the design of dubbo. After dubbo was donated to apache, the package name has been changed. In order to be compatible with the annotations under the old alibaba package, service exposure and service introduction have been designed for easy annotation compatibility. Thanks to this, it is very easy for us to do custom annotation compatibility processing.
Custom comments are passed into the constructor of ReferenceAnnotationBeanPostProcessor:
Public ReferenceAnnotationBeanPostProcessor () {super (AutowiredDubbo.class, Reference.class, com.alibaba.dubbo.config.annotation.Reference.class);}
Add custom annotation support when ServiceAnnotationBeanPostProcessor scanning
Scanner.addIncludeFilter (new AnnotationTypeFilter (Service.class)); / * * Add the compatibility for legacy Dubbo's @ Service * * The issue: https://github.com/apache/dubbo/issues/4330 * @ since 2.7.3 * / scanner.addIncludeFilter (new AnnotationTypeFilter (com.alibaba.dubbo.config.annotation.Service.class)) / / compatible @ DubboService annotation scanner.addIncludeFilter (new AnnotationTypeFilter (DubboService.class))
Finally, modify the service exposure in DubboAutoConfiguration and introduce the service into the processor for our magic implementation.
Configuration compatibility
Self-developed custom configuration is loaded with spring.dubbo. Take the lead, while the official is dubbo. At the beginning, the difference is as follows:
Self-developed configuration: spring.dubbo.application.name = xxxspring.dubbo.registry.address = xxxspring.dubbo.protocol.port =-1 official starter configuration dubbo.application.name = xxxdubbo.registry.address = xxxdubbo.protocol.port =-1
In order to achieve configuration compatibility, the dubbo starter configuration loading logic is modified and spring. Start by modifying the filterDubboProperties in DubboUtils, such as:
Public static SortedMap filterDubboProperties (ConfigurableEnvironment environment) {SortedMap dubboProperties = new TreeMap (); Map properties = EnvironmentUtils.extractProperties (environment); for (Map.Entry entry: properties.entrySet ()) {String propertyName = entry.getKey () If (propertyName.startsWith (DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR) & & entry.getValue ()! = null) {dubboProperties.put (propertyName, entry.getValue (). ToString ()) } if (propertyName.startsWith ("spring." + DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR) & & entry.getValue ()! = null) {propertyName = propertyName.substring (7); dubboProperties.put (propertyName, entry.getValue (). ToString ());} return Collections.unmodifiableSortedMap (dubboProperties);}
Finally, it is packaged and uploaded to the private server. The developer only needs to upgrade the version of jar, and the configuration and code can be upgraded to version 2.7.4.1 dubbo without moving. Maybe the magic change is not just the code posted above. Here is just an idea. This solution ends here. The advantage of this solution is that it is transparent to the development because the steps for migrating to nacos are the same. The second solution will talk about.
Option 2: use the official starter components directly-the final solution
Finally, taking into account the internal maintenance version, when the official upgrade linkage upgrade will be more troublesome, it is better to directly pain a full-line transformation of the code, configuration, using the official starter direct upgrade, so that later version upgrades do not have to invest manpower to maintain self-developed and official consistency.
Step 1: introduce maven dependency
Official dubbo starter dependence
Org.apache.dubbo dubbo-spring-boot-starter 2.7.4.1 com.alibaba.nacos nacos-client 1.1.3 redis.clients jedis 2.9.0 step 2: comments related to renovation
When dubbo is enabled: @ EnableDubbo changes to
@ EnableDubbo [org.apache.dubbo.config.spring.context.annotation.EnableDubbo]
It is also recommended to add a scanBasePackages package path, such as:
@ EnableDubbo (scanBasePackages = "cn.keking.service")
Improve the scanning speed when dubbo exposes and introduces services
When the service is exposed:
Change @ DubboService to @ Service [org.apache.dubbo.config.annotation.Service]
When the service is introduced:
Change @ AutowiredDubbo to @ Reference [org.apache.dubbo.config.annotation.Reference]
There are three points to note here:
1. The default service introduction of the official starter verifies the existence of the service. If there is no exception, it will affect the startup of the application. You can add a global configuration to override the default behavior, as follows: dubbo.consumer.check=false
2. The timeout and other parameters of @ AutowiredDubbo in self-developed starter are in seconds, and the official note @ Reference is in milliseconds. If previously configured as timeout=30, there is only a timeout of 30 milliseconds in the official starter.
3, when using multiple registries, dubbo will introduce services from two registries at the same time, although your URL is exactly the same, it will also generate two service instances locally, so when your fault-tolerant mode is broadcast mode (cluster= "Broadcast") or parallel mode (cluster= "Forking"), consumers will trigger once and producers will receive the problem twice. The default cluster policy is Failover, which will be called normally under random load, and there will be no such problem. If there is a broadcast mode, or parallel mode, you can set up a nacos registry to register only without consumption. The configuration is as follows, and remove the configuration in time after all services are migrated to nacos:
Dubbo.registries.nacos.parameters.subscribe = false
Step 3: modify the configuration of dubbo
Remove spring. Prefix is fine. Note that after upgrading the official starter, you need to add a new configuration to set the connection pool size of redis. The official default is 8.
Dubbo.registries.redis.parameters.max.total = 200
The following example shows the upgraded dubbo configuration:
Dubbo.application.name = xxxdubbo.protocol.port =-1dubbo.provider.timeout = 300000dubbo.consumer.check = falsedubbo.registries.nacos.address = nacos://xxx:80dubbo.registries.redis.address = redis://xxx:6379dubbo.registries.redis.parameters.max.total = 200smooth migration to the nacos registry
Make use of dubbo's feature of supporting multiple registries to complete the smooth migration from redis to nacos in two phases. In the first stage, the whole line is upgraded and modified to dual registries. In the second stage, the redis registry is removed to complete the transition. The configuration is as follows:
Dubbo.registries.nacos.address=nacos://xxx:80dubbo.registries.redis.address=redis://xx:6379
Pay attention to some problems
When using a redis registry, if there is only one redis instance, the differentiated environment is controlled by the db of redis, such as the following configuration:
Dubbo.registry.parameters.db.index = 2
The nacos registry is distinguished by namespaces, and the specific configuration is as follows:
Dubbo.registry.parameters.namespace = xxxxxx
If it is a multi-registry configuration, pay attention to using the relevant registry prefix, such as:
Dubbo.registries.nacos.parameters.namespace=adefa98f-f4d9-4af8-9eb3-e0cab5a39cc7
This is the end of the introduction to "how to upgrade the dubbo2.7.4.1 version and smoothly migrate to the registry nacos". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.