Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query information about clients that subscribe to the specified service - The returned value does not meet expectations #12940

Open
Myheartwilgn opened this issue Dec 12, 2024 · 4 comments

Comments

@Myheartwilgn
Copy link

Myheartwilgn commented Dec 12, 2024

Version:2.2.3~2.3.2
BugApi:Nacos Open API Doc -> /nacos/v2/ns/client/service/subscriber/list
Description:Null is returned when ip or port is null
Code:

  @GetMapping("/service/subscriber/list")
  @Secured(action = ActionTypes.READ, resource = "nacos/admin")
  public Result<List<ObjectNode>> getSubscribeClientList(
          @RequestParam(value = "namespaceId", required = false, defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
          @RequestParam(value = "groupName", required = false, defaultValue = Constants.DEFAULT_GROUP) String groupName,
          @RequestParam(value = "ephemeral", required = false, defaultValue = "true") Boolean ephemeral,
          @RequestParam("serviceName") String serviceName, @RequestParam(value = "ip", required = false) String ip,
          @RequestParam(value = "port", required = false) Integer port) {
      Service service = Service.newService(namespaceId, groupName, serviceName, ephemeral);
      Collection<String> allClientsSubscribeService = clientServiceIndexesManager
              .getAllClientsSubscribeService(service);
      ArrayList<ObjectNode> res = new ArrayList<>();
      for (String clientId : allClientsSubscribeService) {
          Client client = clientManager.getClient(clientId);
          Subscriber subscriber = client.getSubscriber(service);
          if (!Objects.equals(subscriber.getIp(), ip) || !Objects.equals(port, subscriber.getPort())) {
              continue;
          }
          ObjectNode item = JacksonUtils.createEmptyJsonNode();
          item.put("clientId", clientId);
          item.put("ip", subscriber.getIp());
          item.put("port", subscriber.getPort());
          res.add(item);
      }
      return Result.success(res);
  }

BugCode:

    if (!Objects.equals(subscriber.getIp(), ip) || !Objects.equals(port, subscriber.getPort())) {
        continue;
    }
@KomachiSion
Copy link
Collaborator

What's your expected?

@Myheartwilgn
Copy link
Author

What's your expected?
when ip or port is null, don't continue.
Now that the subscriber information is actually found, it is filtered out by "equal" when the ip or port is null, resulting in an empty subscriber list returned.

@KomachiSion
Copy link
Collaborator

So you want when ip or port not input, return all subscribers of this service?

@Myheartwilgn
Copy link
Author

So you want when ip or port not input, return all subscribers of this service?

Yes, in fact, according to the interface documentation, it should be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants