Skip to content

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

Closed
@Myheartwilgn

Description

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;
    }

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions