Getting `Error: 8 RESOURCE_EXHAUSTED: Received message larger than max (15217288 vs. 4194304)` in Node.js gRPC client
Getting `Error: 8 RESOURCE_EXHAUSTED: Received message larger than max (15217288 vs. 4194304)` in Node.js gRPC client
如何增加 Node.js gRPC 客户端的最大消息大小?
我们使用 grpc
、grpc-tools
和 protobufjs
npm-packages:
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());
对于 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
});
如何增加 Node.js gRPC 客户端的最大消息大小?
我们使用 grpc
、grpc-tools
和 protobufjs
npm-packages:
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());
对于 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
});