nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.9k stars 7.55k forks source link

examples/03-microservices: Starting microservice without http server produce error #354

Closed unlight closed 6 years ago

unlight commented 6 years ago

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

async function bootstrap() {
    const app = await NestFactory.create(ApplicationModule);
    const microservice = app.connectMicroservice({ transport: Transport.TCP, port: 43210 });
    await app.startAllMicroservicesAsync();
    // await app.listen(3000); // Is it required? Why?
}
bootstrap();
Service 1: got  { a: 1, b: 2 }
[Nest] 6232   - 2018-1-14 00:02:16   [RpcExceptionsHandler] Cannot read property 'send' of null
TypeError: Cannot read property 'send' of null
    at Service1Controller.doit (\nest-typescript-starter\app\hybrid-example\service1\service1.controller.ts:15:49)
    at RpcContextCreator.<anonymous> (\nest-typescript-starter\node_modules\@nestjs\microservices\context\rpc-context-creator.js:38:33)
    at Generator.next (<anonymous>)
    at fulfilled (\nest-typescript-starter\node_modules\@nestjs\microservices\context\rpc-context-creator.js:4:58)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)

If I uncomment // await app.listen(3000); // Is it required? Why? -> no such error

Expected behavior

No errors.

Minimal reproduction of the problem with instructions

  1. Repo https://github.com/unlight/nest-typescript-starter/tree/bug_2018_2
  2. git clone https://github.com/unlight/nest-typescript-starter
  3. cd nest-typescript-starter
  4. git checkout bug_2018_2
  5. npm install
  6. cd app/hybrid-example
  7. npx ts-node server.ts
  8. npx ts-node client.ts

Result -> Error (see stack trace above)

Environment


Nest version: @nestjs/core@4.5.10

For Tooling issues:
- Node version: XX  v8.9.0
- Platform:  Windows 8
cojack commented 6 years ago

Did you read the docs? https://docs.nestjs.com/microservices/basics

unlight commented 6 years ago

Did you read the docs? docs.nestjs.com/microservices/basics

Yes. And what?

I took code example from nest/examples/03-microservices/src/main.ts Apparantly, it's not correct at the moment or was broken.

Changed code to docs example and it works as expected.

Changed title of the issue.

cojack commented 6 years ago

@unlight I don't know what did you do, but for me it works. Checkout my recorded terminal session: https://asciinema.org/a/ndwZfLnX1leAHj1qKn94E0G0Y

kamilmysliwiec commented 6 years ago

Hi @unlight, You created a hybrid application (https://docs.nestjs.com/faq/hybrid-application). Use createMicroservice() instead (https://docs.nestjs.com/microservices/basics)

gustavosinbandera1 commented 5 years ago

for me work fine

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.