我使用Swift 5.0代码中的Objective-C gRPC库(版本1.24.2) 我在iOS 12.2上运行代码。
服务器是在grpc-go v1.19.0上编写的
syntax = "proto3";
package ...;
message Response {
ServiceStatus status = 1;
}
message ResultStatus {
Status status = 1;
}
enum Status {
OK = 0;
...
}
syntax = "proto3";
package ...;
message Feature {
string name = 1;
bool is_enabled = 2;
int64 valid_until = 3;
}
message QueryFeatures {
}
message ResultFeature {
common.ResultStatus status = 1;
repeated Feature features = 2;
reserved 3;
}
service FeatureTogglingService {
rpc GetFeatures(QueryFeatures) returns (ResultFeature);
}
syntax = "proto3";
package ...;
message CommandSendOnlineStatus {
}
service UserService {
rpc SendOnlineStatus(CommandSendOnlineStatus) returns (Response);
}
我有一个符合GRPCProtoResponseHandler
协议的类,它有一个方法foo
,该方法创建两个服务并从每个服务中调用一个方法:
class MyClass: NSObject, GRPCProtoResponseHandler {
var dispatchQueue: DispatchQueue {
return .main
}
func foo() {
let callOptions = GRPCMutableCallOptions()
callOptions.initialMetadata = ["authorization": "Bearer eyJhbGciO..."]
featureService = FeatureTogglingService(host: "example.com:443", callOptions: callOptions)
userService = UserService(host: "example.com:443", callOptions: callOptions)
let userCall = userService?.sendOnlineStatus(withMessage: userRequest, responseHandler: self, callOptions: nil)
let featureCall = featureService?.getFeaturesWithMessage(featureTogglingRequest, responseHandler: self, callOptions: nil)
featureCall?.start()
userCall?.start()
}
func didReceiveProtoMessage(_ message: GPBMessage?) {
}
func didClose(withTrailingMetadata trailingMetadata: [AnyHashable : Any]?, error: Error?) {
print("??? error: \(error)")
}
}
我调用foo
方法。
我希望看到两次用func didClose(withTrailingMetadata trailingMetadata: [AnyHashable : Any]?, error: Error?)
调用方法error == nil
我看到两次调用方法func didClose(withTrailingMetadata trailingMetadata: [AnyHashable : Any]?, error: Error?)
,其中error
包含:
??? error: Optional(Error Domain=io.grpc Code=13 "{"created":"@1572546519.322425000","description":"Error received from peer ipv4:...:443","file":".../Pods/gRPC-Core/src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"Received RST_STREAM with error code 2","grpc_status":13}" UserInfo={io.grpc.HeadersKey={
date = "Thu, 31 Oct 2019 18:28:39 GMT";
server = nginx;
}, io.grpc.TrailersKey={
}, NSDebugDescription={"created":"@1572546519.322425000","description":"Error received from peer ipv4:...:443","file":".../Pods/gRPC-Core/src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"Received RST_STREAM with error code 2","grpc_status":13}, NSLocalizedDescription=Received RST_STREAM with error code 2})
??? error: Optional(Error Domain=io.grpc Code=13 "{"created":"@1572546519.322339000","description":"Error received from peer ipv4:...:443","file":".../Pods/gRPC-Core/src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"Received RST_STREAM with error code 2","grpc_status":13}" UserInfo={io.grpc.HeadersKey={
date = "Thu, 31 Oct 2019 18:28:39 GMT";
server = nginx;
}, io.grpc.TrailersKey={
}, NSDebugDescription={"created":"@1572546519.322339000","description":"Error received from peer ipv4:...:443","file":".../Pods/gRPC-Core/src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"Received RST_STREAM with error code 2","grpc_status":13}, NSLocalizedDescription=Received RST_STREAM with error code 2})
但是在服务器日志中,我看到由于响应状态为200,所以每个调用都正常。这就是为什么我认为gRPC Objective-C库的客户端存在问题。
我做错了什么?