接口实现:
@Override
public void getFeature(Point request, StreamObserver<Feature> responseObserver) {
responseObserver.onNext(checkFeature(request));
responseObserver.onCompleted();
}
...
private Feature checkFeature(Point location) {
for (Feature feature : features) {
if (feature.getLocation().getLatitude() == location.getLatitude()
&& feature.getLocation().getLongitude() == location.getLongitude()) {
return feature;
}
}
// No feature was found, return an unnamed feature.
return Feature.newBuilder().setName("").setLocation(location).build();
}
Simple RPC:
客户端发起Point请求,服务端返回响应Feature message
整个接口请求响应过程:
1.执行响应过程:onNext()
2.完成接口调用:onCompleted()
@Override
public void getFeature(Point request, StreamObserver<Feature> responseObserver) {
responseObserver.onNext(checkFeature(request));
responseObserver.onCompleted();
}
...
private Feature checkFeature(Point location) {
for (Feature feature : features) {
if (feature.getLocation().getLatitude() == location.getLatitude()
&& feature.getLocation().getLongitude() == location.getLongitude()) {
return feature;
}
}
// No feature was found, return an unnamed feature.
return Feature.newBuilder().setName("").setLocation(location).build();
}
Java gRPC服务创建基础教程
这篇博客介绍了在Java中使用gRPC进行简单RPC服务创建的过程。客户端发送Point请求,服务端响应Feature消息。接口调用流程包括onNext()执行响应和onCompleted()标志着接口调用结束。
5825

被折叠的 条评论
为什么被折叠?



