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
| Parameter | Type | Description |
|---|---|---|
pattern | string | Record<string, unknown> | String or object that identifies this handler. |
transport? | symbol | Transport | Optional 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);
}