alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
29.9k stars 12.77k forks source link

DiscoveryClient does not obtain the latest instance IP address #10547

Closed jixiang-yz closed 1 year ago

jixiang-yz commented 1 year ago

Describe the bug Our service is currently deployed in k8s. I use DiscoveryClient to get all instances in the service, and then send requests to all instances. Sometimes this problem occurs: The host DiscoveryClient obtains is old (it may be old, but it is different from the IP seen on nacos interface), and the correct IP will be obtained after the service restarts.

Whether nacos provides similar java com.net flix. Discovery. DiscoveryClient# refreshRegistry this initiative to refresh approach? Or how do I solve this problem?

List<ServiceInstance> mdInventoryInstances = discoveryClient.getInstances(mdInventoryId);
        for (ServiceInstance instance : mdInventoryInstances) {
            String instanceUri = instance.getUri().toString();
            try {
                // Sometimes ,it is different from the IP seen on nacos interface
                String s = NCApiSupport.httpGet(instanceUri+ mdOfflineGracefullyUrl, mediaTypeHeader);
       }
KomachiSion commented 1 year ago

You should submit this issue to the DiscoveryClient implementation community, not submit to nacos.

jixiang-yz commented 1 year ago

You should submit this issue to the DiscoveryClient implementation community, not submit to nacos.

DiscoveryClient only a interface, it`s not a impl,are you sure????

KomachiSion commented 1 year ago

Of cource, you can see and search in nacos code, there is no depend DiscoveryClient and no DiscoveryClient implementation.

I think you may use an DiscoveryClient implementation such as netflix, alibaba, tecent or other spring cloud implementation.( But I don't know) So you should submit to them, and find out whether they has their own cache in their implementation.

At least, I know the netflix implementation has a long time cache in DiscoveryClient and so that the ip change need a long time to effect, especially in ribbon and feign.

jixiang-yz commented 1 year ago

ok, i try do. thanks!

jixiang-yz commented 1 year ago

Of cource, you can see and search in nacos code, there is no depend DiscoveryClient and no DiscoveryClient implementation.

I think you may use an DiscoveryClient implementation such as netflix, alibaba, tecent or other spring cloud implementation.( But I don't know) So you should submit to them, and find out whether they has their own cache in their implementation.

At least, I know the netflix implementation has a long time cache in DiscoveryClient and so that the ip change need a long time to effect, especially in ribbon and feign.

After debugging, I found that the final implementation it calls is NacosDiscoveryClient, rather than other implementations; What I want to know is how often nacos instances are updated, and how long is the delay if the service IP changes?

image

KomachiSion commented 1 year ago

NacosDiscoveryClient is not implemented by nacos community. all spring cloud implementation want to use nacos as discovery center will implement like this.

You can search in nacos source code, there is no NacosDiscoveryClient.

You should check you maven or gradle file, which spring cloud you used.