Is it possible to (correctly) use multiple Kafka brokers on NestJS hybrid application?

Viewed 59

I'm doing some research on using multiple Kafka brokers on a NestJS hybrid application, and altough I know it's possibleI can't find the answer for wether it's not a bad practice or wrong at all to do it and if it's possible to do it without a workaround or not.

Not sure if it matters, but I'm currently using Event Hubs as my Kafka provider and I have two different namespaces (thus, two different brokers with different connection strings) with different topics (events) on each of them.

Right now, my main looks like this:


(async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    logger: WinstonModule.createLogger(winstonTransports),
  });

  app.connectMicroservice<MicroserviceOptions>(kafkaConfig);

  const logger = app.get<winston.Logger>(WINSTON_MODULE_NEST_PROVIDER);
  app.useLogger(logger);
  app.enableCors(corsConfig);

  await app.startAllMicroservices();
  await app.listen(env.PORT);
})().catch(() => {});

KafkaModule:

@Module({
  controllers: [],
  imports: [ClientsModule.register([kafkaConfig])],
  providers: [KafkaService, LoggerService],
  exports: [KafkaService],
})
export class KafkaModule {}

Any ideas? Might I do it (without side effects) just by using app.createMicroService(kafkaConfig2) to create my second kafka broker?

0 Answers
Related