After Nacos started, the client worker log was printed all the time

After Nacos started, the client worker log was printed all the time

Phenomenon

Print the clientworker log all the time

2020-08-24 00:57:30.977 INFO  [12932] --- [.cn_8848-public] c.a.n.client.config.impl.ClientWorker    : [fixed-nacos.itlym.cn_8848-public] [data-received] dataId=common.yml, group=DEFAULT_GROUP, tenant=public, md5=8c191cace81179b01fb745b5d027c1c8, content=xxx
2020-08-24 00:57:30.989 INFO  [12932] --- [.cn_8848-public] c.a.n.client.config.impl.ClientWorker    : [fixed-nacos.itlym.cn_8848-public] [data-received] dataId=sms-center.yml, group=DEFAULT_GROUP, tenant=public, md5=f12bc945ba0c1d39f3dea2e0977db712, content=xxx
...

Cause analysis

Root cause

Having seen the source code of Nacos before, Nacos will check whether the configuration items are consistent with the server configuration items every 10ms. If not, it will pull the latest configuration from the server therefore, if the MD5 algorithms of Nacos client and Nacos server are different, it will lead to misjudgment, thus constantly refreshing and printing the client worker logs.

Direct cause

My Nacos server is 1.3, and the client uses spring cloud Alibaba. Version . Click to find that the Nacos client version is 1.2

			<dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

Here, the spring-cloud-alibaba-dependencies‘s official website and warehouse have not been updated for a long time, which is easy to make complaints about users and waste a lot of investigation time.

Other possible reasons

The public is set in the namespace. See the Nacos GitHub

At this time, the best way to solve this problem is not to set the namespace. Otherwise, when Nacos releases a new version, it may be 1.4

Solution

Method 1:

Change the version of client and Nacos server to the same, as follows

client:
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>${spring-cloud-alibaba.version}</version>
    <type>pom</type>
    <scope>import</scope>
    <exclusions>
    <exclusion>
        <artifactId>com.alibaba.nacos</artifactId>
        <groupId>nacos-client</groupId>
    </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.alibaba.nacos</groupId>
    <artifactId>nacos-client</artifactId>
    <version>1.3.2</version>
</dependency>

Method 2:

Because spring cloud Alibaba dependencies leaves the gap of properties specified version (default < nacos.client.version> 1.2.1)
so you only need to add

<properties>
	<nacos.client.version>1.2.1</nacos.client.version>
</properties>

Note: if spring cloud starter Nacos config is introduced, it can’t be avoided by this scheme, because ‘spring cloud Alibaba dependencies’ has hard coding problems. When importing, you should actively specify the version.

			 <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
                <version>1.3.0</version>
            </dependency>

Method 3 (middleware upgrade scheme suitable for existing system):

Download the Nacos client Version 1.2.1 code, modify its md5util package path to a new one, and then re publish it to the local or private warehouse.

Read More: