【发布时间】:2020-12-27 07:23:42
【问题描述】:
为什么无法从 JMeter 的 BeanShell 采样器中运行本机 Java gRPC 客户端:
package at.fhj.swd.grpc.client;
import at.fhj.swd.grpc.CalcRequest;
import at.fhj.swd.grpc.CalcResponse;
import at.fhj.swd.grpc.CalcServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
public class GrpcClient {
public static void calc() {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9090)
.usePlaintext()
.build();
CalcServiceGrpc.CalcServiceBlockingStub stub
= CalcServiceGrpc.newBlockingStub(channel);
CalcResponse calcResponse = stub.calc(CalcRequest.newBuilder()
.setNumber(7)
.build());
channel.shutdown();
System.out.println(calcResponse.getResultList());
}
}
BeanShell 采样器脚本无法创建 GrpcCient 的实例。 (引用方法调用)
import at.fhj.swd.grpc.client.GrpcClient;
GrpcClient grpcClient = new GrpcClient();
//grpcClient.calc();
错误:
Response code:500
Response message:org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval io/grpc/Channel
似乎导入有问题,但为什么呢?如果在没有 JMeter 的情况下执行,则客户端运行。
【问题讨论】:
-
ManagedChannel 扩展了 Channel,但为什么会出现问题?