Skip to content

Commit da110d0

Browse files
committed
use getOptionsProp method on grcp max_send_message_length & max_receive_message_length implementation
1 parent bd3222a commit da110d0

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

packages/microservices/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ export const RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT = false;
2727
export const RQM_DEFAULT_QUEUE_OPTIONS = {};
2828

2929
export const GRPC_DEFAULT_PROTO_LOADER = '@grpc/proto-loader';
30+
export const GRPC_DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH = 4 * 1024 * 1024;
31+
export const GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH = 4 * 1024 * 1024;

packages/microservices/server/server-grpc.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { fromEvent } from 'rxjs';
22
import { takeUntil } from 'rxjs/operators';
3-
import { CANCEL_EVENT, GRPC_DEFAULT_PROTO_LOADER, GRPC_DEFAULT_URL } from '../constants';
3+
import {
4+
CANCEL_EVENT,
5+
GRPC_DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH,
6+
GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH,
7+
GRPC_DEFAULT_PROTO_LOADER,
8+
GRPC_DEFAULT_URL
9+
} from '../constants';
410
import { InvalidGrpcPackageException } from '../exceptions/errors/invalid-grpc-package.exception';
511
import { InvalidProtoDefinitionException } from '../exceptions/errors/invalid-proto-definition.exception';
612
import { CustomTransportStrategy } from '../interfaces';
@@ -15,20 +21,13 @@ let grpcProtoLoaderPackage: any = {};
1521

1622
export class ServerGrpc extends Server implements CustomTransportStrategy {
1723
private readonly url: string;
18-
private readonly maxSendMessageLength: number;
19-
private readonly maxReceiveMessageLength: number;
2024
private grpcClient: any;
2125

2226
constructor(private readonly options: MicroserviceOptions['options']) {
2327
super();
2428
this.url =
2529
this.getOptionsProp<GrpcOptions>(options, 'url') || GRPC_DEFAULT_URL;
2630

27-
this.maxSendMessageLength =
28-
this.getOptionsProp<GrpcOptions>(options, 'maxSendMessageLength') || GRPC_DEFAULT_URL;
29-
this.maxReceiveMessageLength =
30-
this.getOptionsProp<GrpcOptions>(options, 'maxReceiveMessageLength') || GRPC_DEFAULT_URL;
31-
3231
const protoLoader =
3332
this.getOptionsProp<GrpcOptions>(options, 'protoLoader') || GRPC_DEFAULT_PROTO_LOADER;
3433

@@ -145,8 +144,8 @@ export class ServerGrpc extends Server implements CustomTransportStrategy {
145144

146145
public createClient(): any {
147146
const server = new grpcPackage.Server({
148-
...this.maxSendMessageLength ? { 'grpc.max_send_message_length': this.maxSendMessageLength } : {},
149-
...this.maxReceiveMessageLength ? { 'grpc.max_receive_message_length': this.maxReceiveMessageLength } : {}
147+
'grpc.max_send_message_length': this.getOptionsProp<GrpcOptions>(this.options, 'maxSendMessageLength', GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH),
148+
'grpc.max_receive_message_length': this.getOptionsProp<GrpcOptions>(this.options, 'maxReceiveMessageLength', GRPC_DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH)
150149
});
151150
const credentials = this.getOptionsProp<GrpcOptions>(
152151
this.options,

0 commit comments

Comments
 (0)