@Override public String getServiceName() { return refUrl.getServiceInterface(); }
@Override public String getServiceName() { return refUrl.getServiceInterface(); }
public String getRpcName() { return this.providerUrl.getServiceInterface() + ":" + method.getName(); }
public static String toRoutePath(GrpcURL url) { String name = url.getServiceInterface(); String group = url.getGroup(); return Constants.CONSUL_SERVICE_PRE + group + Constants.PATH_SEPARATOR + name; }
public DefaultProxyClient(GrpcURL refUrl) { this.refUrl = refUrl; String serviceName = refUrl.getServiceInterface(); try { this.interfaceClass = ReflectUtils.name2class(serviceName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
public static Map<String, Object> getAffinity(final GrpcURL refUrl) { String serviceName = refUrl.getServiceInterface(); return CACHEOPTIONS_CACHE.get(serviceName).getOption(CALLOPTIONS_CUSTOME_KEY); }
public static CallOptions createCallOptions(final GrpcURL refUrl) { String serviceName = refUrl.getServiceInterface(); CallOptions options = CACHEOPTIONS_CACHE.get(serviceName); if (options == null) { ConcurrentHashMap<String, Object> customOptions = new ConcurrentHashMap<String, Object>(); customOptions.put(GRPC_REF_URL, refUrl); options = CallOptions.DEFAULT.withOption(CALLOPTIONS_CUSTOME_KEY, customOptions); CACHEOPTIONS_CACHE.put(serviceName, options); return options; } else { return options; } }
public String getServiceKey() { String inf = getServiceInterface(); if (inf == null) return null; StringBuilder buf = new StringBuilder(); String group = getGroup(); if (group != null && group.length() > 0) { buf.append(group).append("/"); } buf.append(inf); String version = getVersion(); if (version != null && version.length() > 0) { buf.append(":").append(version); } return buf.toString(); }
public GrpcServerStrategy(GrpcURL providerUrl, Object protocolImpl){ if (protocolImpl instanceof BindableService) { this.exporter = new GrpcStubServerExporter(); this.protocolClass = protocolImpl.getClass(); } else { Class<?> protocol; try { protocol = ReflectUtils.name2class(providerUrl.getServiceInterface()); if (!protocol.isAssignableFrom(protocolImpl.getClass())) { throw new IllegalStateException("protocolClass " + providerUrl.getServiceInterface() + " is not implemented by protocolImpl which is of class " + protocolImpl.getClass()); } } catch (ClassNotFoundException e) { protocol = protocolImpl.getClass(); } this.protocolClass = protocol; this.exporter = new DefaultProxyExporter(providerUrl); } this.protocolImpl = protocolImpl; }
private static String toServicePath(GrpcURL url) { String name = url.getServiceInterface(); String group = url.getGroup(); return group + Constants.PATH_SEPARATOR + GrpcURL.encode(name); }
public static boolean isMatch(GrpcURL subscribedUrl, GrpcURL providerUrl) { String subscribedInterface = subscribedUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (StringUtils.equals(subscribedInterface, providerInterface)) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true)) { return false; } String subscribedGroup = subscribedUrl.getGroup(); String subscribedVersion = subscribedUrl.getVersion(); String providerGroup = providerUrl.getGroup(); String providerVersion = providerUrl.getVersion(); return StringUtils.equals(subscribedGroup, providerGroup) && StringUtils.equals(subscribedVersion, providerVersion); }
private void streamCall(Message request, StreamObserver<Message> responseObserver) { try { Class<?> requestType = grpcMethodType.requestType(); Object reqPojo = SerializerUtil.protobuf2Pojo(request, requestType); Object[] requestParams = new Object[] {reqPojo, PoJo2ProtoStreamObserver.newObserverWrap(responseObserver)}; method.invoke(serviceToInvoke, requestParams); } catch (Throwable e) { String stackTrace = ThrowableUtil.stackTraceToString(e); log.error(e.getMessage(), e); StatusRuntimeException statusException = Status.UNAVAILABLE.withDescription(stackTrace).asRuntimeException(); responseObserver.onError(statusException); } finally { log.debug(String.format("Service: %s Method: %s RemoteAddress: %s", providerUrl.getServiceInterface(), method.getName(), this.remote)); } }
} finally { log.info(String.format("Service: %s Method: %s RemoteAddress: %s", providerUrl.getServiceInterface(), method.getName(), this.remote)); getConcurrent().decrementAndGet();
String service = providerUrl.getServiceInterface(); // 获取服务名称 String method = this.method.getName(); // 获取方法名 String consumer = this.remote;// 远程服务器地址
@Override public StreamObserver<Message> invoke(StreamObserver<Message> responseObserver) { try { this.remote = RpcContext.getContext().getAttachment(Constants.REMOTE_ADDRESS); Class<?> requestType = grpcMethodType.requestType(); PoJo2ProtoStreamObserver servserResponseObserver = PoJo2ProtoStreamObserver.newObserverWrap(responseObserver); Object result = method.invoke(serviceToInvoke, servserResponseObserver); return Proto2PoJoStreamObserver.newObserverWrap((StreamObserver<Object>) result, requestType); } catch (Throwable e) { String stackTrace = ThrowableUtil.stackTraceToString(e); log.error(e.getMessage(), e); StatusRuntimeException statusException = Status.UNAVAILABLE.withDescription(stackTrace).asRuntimeException(); responseObserver.onError(statusException); } finally { log.debug(String.format("Service: %s Method: %s RemoteAddress: %s", providerUrl.getServiceInterface(), method.getName(), this.remote)); } return null; }
invoke.setService(statistics.getServiceInterface()); invoke.setMethod(statistics.getParameter(METHOD)); invoke.setConcurrent(statistics.getParameter(CONCURRENT, 1));