为什么不能在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的情况下执行客户端,则客户端将运行。
发布于 2020-12-27 17:51:11
groovy就足够了,你的代码就会按预期开始工作。此外,与Beanshell相比,具有更好的性能,有关
Groovy的更多详细信息,请参阅Apache Groovy - Why and How You Should Use It文章
https://stackoverflow.com/questions/65463657
复制相似问题