NestJS - Combine HTTP with RabbitMQ in microservices

后端 未结 1 1446
走了就别回头了
走了就别回头了 2021-01-13 13:26

I have a few microservices, which are exposed through an API-Gateway. The gateway takes care of handling authentication and routing into the system. The services behind the

相关标签:
1条回答
  • 2021-01-13 13:55

    RabbitMQ is supported in nestjs as a microservice. If you want your application to support both http requests and a message broker, you can create a hybrid application.

    // Create your regular nest application.
    const app = await NestFactory.create(ApplicationModule);
    
    // Then combine it with a RabbitMQ microservice
    const microservice = app.connectMicroservice({
      transport: Transport.RMQ,
      options: {
        urls: [`amqp://localhost:5672`],
        queue: 'my_queue',
        queueOptions: { durable: false },
      },
    });
    
    await app.startAllMicroservicesAsync();
    await app.listen(3001);
    
    0 讨论(0)
提交回复
热议问题