diff --git a/sdk/src/index.ts b/sdk/src/index.ts index a926118f..265a02e1 100644 --- a/sdk/src/index.ts +++ b/sdk/src/index.ts @@ -25,6 +25,7 @@ export { ReplicatedWriteConsistency, ServiceBinding, PreStartSettings, + ChannelSettings, } from './kalix'; export { Action } from './action'; diff --git a/sdk/src/kalix.ts b/sdk/src/kalix.ts index ce90d764..e1416f9f 100644 --- a/sdk/src/kalix.ts +++ b/sdk/src/kalix.ts @@ -66,6 +66,11 @@ export interface KalixOptions { * Delay completing discovery until proxyPort has been set by the testkit. */ delayDiscoveryUntilProxyPortSet?: boolean; + + /** + * Channel settings. + */ + channelSettings?: ChannelSettings; } /** @internal */ @@ -266,6 +271,22 @@ export interface PreStartSettings { identificationInfo?: discovery.IdentificationInfo; } +/** + * Settings for the gRPC channel used to communicate with the Kalix proxy + * + * @public + */ +export interface ChannelSettings { + /** + * The maximum number of bytes a gRPC message may be when receiving + */ + maxReceiveMessageLength?: number; + /** + * The maximum number of bytes a gRPC message may be when sending + */ + maxSendMessageLength?: number; +} + /** * Kalix Entity. * @@ -430,7 +451,9 @@ export class Kalix { ); } - this.server = new grpc.Server(); + this.server = new grpc.Server( + this.channelSettingsToGrpcChannelOptions(options?.channelSettings), + ); } /** @@ -780,6 +803,21 @@ export class Kalix { return spec; } + private channelSettingsToGrpcChannelOptions( + settings?: ChannelSettings, + ): grpc.ChannelOptions { + const opts = { + 'grpc.max_receive_message_length': settings?.maxReceiveMessageLength, + 'grpc.max_send_message_length': settings?.maxSendMessageLength, + }; + if (!opts['grpc.max_receive_message_length']) { + // Default to 12 mb + opts['grpc.max_receive_message_length'] = 12 * 1024 * 1024; + } + + return opts; + } + private proxyTerminatedLogic() { this.proxyHasTerminated = true; if (this.waitingForProxyTermination) {