Skip to content

Microservices interaction with external services #406

Open
@purplefish32

Description

@purplefish32

I'm submitting a...


[ ] Regression 
[X ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When using nestjs as a NATS microservice, the nats payload (data), when using the @MessagePattern decorator, is always undefined.

  @MessagePattern('sms.send')
  test(data: any) {
    console.log('function called OK');
    console.log(data); // Allways undefined
  }

In the provided example I can log "function called OK" but data is allways undefined.

Here is my main.ts

import { NestFactory } from '@nestjs/core';
import { Transport } from '@nestjs/microservices';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, {
    transport: Transport.NATS,
    options: {
      url: 'nats://nats:4222',
      queue: 'sms',
    },
  });
  app.listen(() => console.log('Microservice is listening'));
}
bootstrap();

I have tried both regular strings and json encoded objects as valid payloads.

Expected behavior

data should not be undefined

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions