Skip to content

Commit 25dbb33

Browse files
committed
Alligned gRPC ChannelOptions code in server and client.
Removed GRPC_DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH and GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH constants. This default values are already the same in the underlying gRPC library. If the gRPC team decides to change that values in the future, nestjs should adopt the new values automatically.
1 parent e88e310 commit 25dbb33

3 files changed

Lines changed: 11 additions & 29 deletions

File tree

packages/microservices/client/client-grpc.ts

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { loadPackage } from '@nestjs/common/utils/load-package.util';
33
import { isFunction, isObject } from '@nestjs/common/utils/shared.utils';
44
import { Observable, Subscription } from 'rxjs';
55
import {
6-
GRPC_DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH,
7-
GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH,
86
GRPC_DEFAULT_PROTO_LOADER,
97
GRPC_DEFAULT_URL,
108
} from '../constants';
@@ -14,6 +12,7 @@ import { InvalidProtoDefinitionException } from '../errors/invalid-proto-definit
1412
import { ClientGrpc, GrpcOptions } from '../interfaces';
1513
import { ClientProxy } from './client-proxy';
1614
import { GRPC_CANCELLED } from './constants';
15+
import {ChannelOptions} from "../external/grpc-options.interface";
1716

1817
let grpcPackage: any = {};
1918
let grpcProtoLoaderPackage: any = {};
@@ -65,33 +64,20 @@ export class ClientGrpcProxy extends ClientProxy implements ClientGrpc {
6564
throw new InvalidGrpcServiceException();
6665
}
6766

68-
const maxSendMessageLengthKey = 'grpc.max_send_message_length';
69-
const maxReceiveMessageLengthKey = 'grpc.max_receive_message_length';
70-
const maxMessageLengthOptions = {
71-
[maxSendMessageLengthKey]: this.getOptionsProp(
72-
this.options,
73-
'maxSendMessageLength',
74-
GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH,
75-
),
76-
[maxReceiveMessageLengthKey]: this.getOptionsProp(
77-
this.options,
78-
'maxReceiveMessageLength',
79-
GRPC_DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH,
80-
),
81-
};
82-
const maxMetadataSize = this.getOptionsProp(
83-
this.options,
84-
'maxMetadataSize',
85-
-1,
86-
);
87-
if (maxMetadataSize > 0) {
88-
maxMessageLengthOptions['grpc.max_metadata_size'] = maxMetadataSize;
67+
const channelOptions: ChannelOptions = this.options && this.options.channelOptions ? this.options.channelOptions : {};
68+
if (this.options && this.options.maxSendMessageLength) {
69+
channelOptions["grpc.max_send_message_length"] = this.options.maxSendMessageLength;
70+
}
71+
if (this.options && this.options.maxReceiveMessageLength) {
72+
channelOptions["grpc.max_receive_message_length"] = this.options.maxReceiveMessageLength;
73+
}
74+
if (this.options && this.options.maxMetadataSize) {
75+
channelOptions["grpc.max_metadata_size"] = this.options.maxMetadataSize;
8976
}
9077

9178
const keepaliveOptions = this.getKeepaliveOptions();
9279
const options: Record<string, string | number> = {
93-
...(this.options.channelOptions || {}),
94-
...maxMessageLengthOptions,
80+
...channelOptions,
9581
...keepaliveOptions,
9682
};
9783

packages/microservices/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ export const GRPC_DEFAULT_PROTO_LOADER = '@grpc/proto-loader';
3939
export const NO_MESSAGE_HANDLER = `There is no matching message handler defined in the remote service.`;
4040
export const NO_EVENT_HANDLER = `There is no matching event handler defined in the remote service.`;
4141
export const DISCONNECTED_RMQ_MESSAGE = `Disconnected from RMQ. Trying to reconnect.`;
42-
export const GRPC_DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH = 4 * 1024 * 1024;
43-
export const GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH = 4 * 1024 * 1024;
4442

4543
export const KAFKA_DEFAULT_CLIENT = 'nestjs-consumer';
4644
export const KAFKA_DEFAULT_GROUP = 'nestjs-group';

packages/microservices/server/server-grpc.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { EMPTY, fromEvent, lastValueFrom, Subject } from 'rxjs';
77
import { catchError, takeUntil } from 'rxjs/operators';
88
import {
99
CANCEL_EVENT,
10-
GRPC_DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH,
11-
GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH,
1210
GRPC_DEFAULT_PROTO_LOADER,
1311
GRPC_DEFAULT_URL,
1412
} from '../constants';

0 commit comments

Comments
 (0)