use of org.apache.shenyu.common.enums.RpcTypeEnum in project incubator-shenyu by apache.
the class ShenyuPlugin method skip.
/**
* plugin is executed.
* if return true this plugin can not execute.
*
* <p>the same for:
* <pre>
* <code>Objects.equals(rpcType, typeA.getName())
* || Objects.equals(rpcType, typeB.getName())
* || Objects.equals(rpcType, type...getName())
* </code>
* </pre>
*
* @param exchange the current server exchange
* @param rpcTypes the skip rpc type list
* @return current rpcType == someone rpcType
*/
default boolean skip(ServerWebExchange exchange, RpcTypeEnum... rpcTypes) {
if (ArrayUtils.isEmpty(rpcTypes)) {
return false;
}
ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
assert shenyuContext != null;
String rpcType = shenyuContext.getRpcType();
for (final RpcTypeEnum type : rpcTypes) {
if (Objects.equals(rpcType, type.getName())) {
return true;
}
}
return false;
}
use of org.apache.shenyu.common.enums.RpcTypeEnum in project incubator-shenyu by apache.
the class NacosServerRegisterRepository method subscribeRpcTypeService.
private void subscribeRpcTypeService(final RpcTypeEnum rpcType) {
final String serviceName = RegisterPathConstants.buildServiceInstancePath(rpcType.getName());
try {
Map<String, List<URIRegisterDTO>> services = new HashMap<>();
List<Instance> healthyInstances = namingService.selectInstances(serviceName, true);
healthyInstances.forEach(healthyInstance -> {
String contextPath = healthyInstance.getMetadata().get("contextPath");
String serviceConfigName = RegisterPathConstants.buildServiceConfigPath(rpcType.getName(), contextPath);
subscribeMetadata(serviceConfigName);
metadataConfigCache.add(serviceConfigName);
String metadata = healthyInstance.getMetadata().get("uriMetadata");
URIRegisterDTO uriRegisterDTO = GsonUtils.getInstance().fromJson(metadata, URIRegisterDTO.class);
services.computeIfAbsent(contextPath, k -> new ArrayList<>()).add(uriRegisterDTO);
uriServiceCache.computeIfAbsent(serviceName, k -> new ConcurrentSkipListSet<>()).add(contextPath);
});
if (RPC_URI_TYPE_SET.contains(rpcType)) {
services.values().forEach(this::publishRegisterURI);
}
LOGGER.info("subscribe uri : {}", serviceName);
namingService.subscribe(serviceName, event -> {
if (event instanceof NamingEvent) {
List<Instance> instances = ((NamingEvent) event).getInstances();
instances.forEach(instance -> {
String contextPath = instance.getMetadata().get("contextPath");
uriServiceCache.computeIfAbsent(serviceName, k -> new ConcurrentSkipListSet<>()).add(contextPath);
});
refreshURIService(rpcType, serviceName);
}
});
} catch (NacosException e) {
throw new ShenyuException(e);
}
}
Aggregations