我继续研究这个gattle/grpc,我把我的代码放在一起如下,代码定义来自这里
class BasicSimu extends Simulation {
val TokenKey : String = "token-string"
val grpcConf = grpc(managedChannelBuilder("url:80").usePlaintext())
.header(util.BearerToken, optional = true)($(TokenKey))
.shareChannel
val thisStream: ClientStream [StartPairingRequest, StartPairing Response] = grpc("Speak").clientStream(RelayServerGrpc.METHOD_START_PAIRING, "gettingThePairingKey")
val speaker = scenario("BasicSimu")
.exec(
thisStream.connect
)
setUp(
speaker.inject(atOnceUsers(1))
).protocols(grpcConf)
}
目前,我想要实现的目标是从客户端调用服务器创建一个流,然后从中获取数据。当我编译时,我收到以下错误日志:
[error] C:\Users\...\BasicSimu.scala:34:19: not found: type ClientStream
[error] val thisStream: ClientStream[StartPairingRequest, StartPairingResponse] = grpc("Speak").clientStream(RelayServerGrpc.METHOD_START_PAIRING, "gettingThePairingKey")
我也尝试过 bidiStream 方法,错误也类似,代码遵循 phiSgr 的示例。以下是原始定义:
rpc StartPairing(StartPairingRequest) returns (stream StartPairingResponse) {
option (google.api.http) = {
post: "/v1/pairing"
body: "*"
};
生成的 METHOD_START_PAIRING
val METHOD_START_PAIRING: root.io.grpc.MethodDescriptor[package.StartPairingRequest, package.StartPairingResponse] =
root.io.grpc.MethodDescriptor.newBuilder()
.setType(root.io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
.setFullMethodName(root.io.grpc.MethodDescriptor.generateFullMethodName("relay.RelayServer", "StartPairing"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(root.scalapb.grpc.Marshaller.forMessage[package.StartPairingRequest])
.setResponseMarshaller(root.scalapb.grpc.Marshaller.forMessage[package.StartPairingResponse])
.setSchemaDescriptor(root.scalapb.grpc.ConcreteProtoMethodDescriptorSupplier.fromMethodDescriptor(package.javaDescriptor.getServices().get(0).getMethods().get(0)))
.build()
我在这里传错了什么参数?
根据我的问题,这是答案
import com.github.phisgr.gatling.grpc.request._