Skip to content

Function: MessagePattern()

ts
function MessagePattern(pattern, transport?): MethodDecorator;

Defined in: packages/microservices/src/decorators/message-pattern.decorator.ts:22

Marks a controller method as a request-response message handler. The method is called when a client sends a message matching pattern and it is expected to return a response.

Parameters

ParameterTypeDescription
patternstring | Record<string, unknown>String or object that identifies this handler.
transport?symbol | TransportOptional transport override; defaults to the server's transport.

Returns

MethodDecorator

Example

typescript
@MessagePattern('sum')
accumulate(@Payload() data: number[]): number {
  return data.reduce((a, b) => a + b, 0);
}

Released under the MIT License.