Skip to content

Commit

Permalink
add isSubscribed
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiaofeng committed Jan 27, 2025
1 parent d7c48df commit 776027c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ public void update(String service, List<? extends Endpoint> endpoints) {
}
}

@Override
public boolean isSubscribed(String service) {
return service != null && !service.isEmpty() && subscriptions.containsKey(service);
}

/**
* Called when the application is ready to start. This method iterates through all registered services and calls their register method.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ public interface RegistrySupervisor extends Registry {
* @param endpoints the new list of endpoints for the service group
*/
void update(String service, List<? extends Endpoint> endpoints);

/**
* Checks if the registry is subscribed to a specific service.
*
* @param service the service
* @return true if the registry is subscribed to the service, false otherwise
*/
boolean isSubscribed(String service);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import com.jd.live.agent.governance.registry.RegistrySupervisor;
import com.jd.live.agent.plugin.registry.nacos.instance.NacosEndpoint;

import java.util.List;

import static com.jd.live.agent.core.util.CollectionUtils.toList;

/**
Expand All @@ -41,9 +39,8 @@ public NacosInstanceChangeInterceptor(RegistrySupervisor supervisor) {
public void onSuccess(ExecutableContext ctx) {
MethodContext mc = (MethodContext) ctx;
InstancesChangeEvent event = mc.getArgument(0);
List<NacosEndpoint> endpoints = toList(event.getHosts(), NacosEndpoint::new);
// get group from meta
supervisor.update(event.getServiceName(), endpoints);

if (supervisor.isSubscribed(event.getServiceName())) {
supervisor.update(event.getServiceName(), toList(event.getHosts(), NacosEndpoint::new));
}
}
}

0 comments on commit 776027c

Please sign in to comment.