3

如何增加 Node.js gRPC 客户端的最大消息大小?

我们使用grpc,grpc-toolsprotobufjsnpm 包:

  const packageDefinitions = loader.loadSync(PROTO_PATH, { includeDirs: [__dirname], longs: String, arrays: true });
  const packageObject = grpc.loadPackageDefinition(packageDefinitions);
  const client = new packageObject.Service(serviceAddress, grpc.credentials.createInsecure());
4

1 回答 1

8

对于 gRPC 客户端和服务器,我们可以指定 gRPC 参数。例如,将最大消息大小设置为 100 Mb:

客户

  const client = new packageObject.Service(serviceAddress, grpc.credentials.createInsecure(), {
    "grpc.max_receive_message_length": 1024 * 1024 * 100,
    "grpc.max_send_message_length": 1024 * 1024 * 100
  });

服务器

  const server = new grpc.Server({
    "grpc.max_receive_message_length": 1024 * 1024 * 100,
    "grpc.max_send_message_length": 1024 * 1024 * 100
  });
于 2019-06-26T08:17:23.417 回答