use of com.tencent.polaris.plugins.connector.grpc.Connection in project polaris-java by polarismesh.
the class PolarisConfigFileConnector method getConfigFile.
@Override
public ConfigFileResponse getConfigFile(ConfigFile configFile) {
Connection connection = null;
try {
connection = connectionManager.getConnection(OP_KEY_GET_CONFIG_FILE, ClusterType.SERVICE_DISCOVER_CLUSTER);
// grpc 调用
PolarisConfigGRPCGrpc.PolarisConfigGRPCBlockingStub stub = PolarisConfigGRPCGrpc.newBlockingStub(connection.getChannel());
// 附加通用 header
GrpcUtil.attachRequestHeader(stub, GrpcUtil.nextInstanceRegisterReqId());
// 执行调用
ConfigFileProto.ConfigFileResponse response = stub.getConfigFile(transfer2DTO(configFile));
return handleResponse(response);
} catch (Throwable t) {
// 网络访问异常
if (connection != null) {
connection.reportFail();
}
throw new RetriableException(ErrorCode.NETWORK_ERROR, String.format("failed to load config file. namespace = %s, group = %s, file = %s", configFile.getNamespace(), configFile.getFileGroup(), configFile.getFileName()), t);
} finally {
if (connection != null) {
connection.release(OP_KEY_GET_CONFIG_FILE);
}
}
}
use of com.tencent.polaris.plugins.connector.grpc.Connection in project polaris-java by polarismesh.
the class PolarisConfigFileConnector method watchConfigFiles.
@Override
public ConfigFileResponse watchConfigFiles(List<ConfigFile> configFiles) {
Connection connection = null;
try {
connection = connectionManager.getConnection(OP_KEY_GET_CONFIG_FILE, ClusterType.SERVICE_DISCOVER_CLUSTER);
// grpc 调用
PolarisConfigGRPCGrpc.PolarisConfigGRPCBlockingStub stub = PolarisConfigGRPCGrpc.newBlockingStub(connection.getChannel());
// 附加通用 header
GrpcUtil.attachRequestHeader(stub, GrpcUtil.nextInstanceRegisterReqId());
// 执行调用
List<ConfigFileProto.ConfigFileDTO> dtos = Lists.newLinkedList();
for (ConfigFile configFile : configFiles) {
dtos.add(transfer2DTO(configFile));
}
ConfigFileProto.WatchConfigFileRequest request = ConfigFileProto.WatchConfigFileRequest.newBuilder().addAllWatchFiles(dtos).build();
ConfigFileProto.ConfigFileResponse response = stub.watchConfigFiles(request);
return handleResponse(response);
} catch (Throwable t) {
// 网络访问异常
if (connection != null) {
connection.reportFail();
}
throw new RetriableException(ErrorCode.NETWORK_ERROR, "[Config] failed to watch config file", t);
} finally {
if (connection != null) {
connection.release(OP_KEY_GET_CONFIG_FILE);
}
}
}
Aggregations