Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

310
Vistas
how to use RabbitMQ and REST-API in Nest App?

Good Day!

I'm trying to implement 2 microservices that communicate with each other through a message broker. But one of them should accept Http requests via REST-Api. Unfortunately, I don't understand how to make the microservice listen to both the message queue and incoming HTTP requests. Perhaps I don’t understand something in the paradigm of communication through a message broker, but how then to receive requests from the client and forward them to the microservice architecture?

Main.ts

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

async function bootstrap() {
  const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
    transport: Transport.RMQ,
    options: {
      urls: ['amqp://rabbitmq:5672'],
      queue: 'hello_world',
      queueOptions: {
        durable: false
      },
    },
  });
  await app.listen();
}
bootstrap();

As you can see, now the application is not listening on port 3000 as in the standard approach. What should be done?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The answer turned out to be quite simple. NEST js has hybrid apps. You can get to know them here https://docs.nestjs.com/faq/hybrid-application#hybrid-application. Thanks everyone

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

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const microservice = app.connectMicroservice({
    transport: Transport.RMQ,
    options: {
      urls: ['amqp://rabbitmq:5672'],
      queue: 'hello_world',
      queueOptions: {
        durable: false
      },
    },
  });

  await app.startAllMicroservices();
  await app.listen(3000);
}
bootstrap();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda