Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Nestjs microservice

i have create my first microservice project with nest using kafka but I am stuck in a dilemma

Right now in API gateway i make every module a microservice client for example i have user component and in this component i created CQRS module and in this module i have created a connection to kafka and so on . Now i wonder this is a good approach or should i make one connection for all components?

import { Module } from '@nestjs/common';
import { CreateUserCommand } from './commands/impl/create-user.command';
import { CqrsModule } from '@nestjs/cqrs';
import {
  ClientsModule,
  ClientsProviderAsyncOptions,
} from '@nestjs/microservices';
import { UserClient } from '../user.enum';
import { MicroServiceConfigModule } from '../../../config/microservice/config.module';
import { MicroServiceConfigService } from '../../../config/microservice/config.service';
import {
  KafkaClientProviderOptionsFactory,
  RegisterConfig,
} from '../../../factory';
import { UserCreatedEvent } from './events/impl/user-created.event';
import { CommandHandlers } from './commands/handlers';
import { EventHandlers } from './events/handlers';
import { UserSaga } from './user.saga';

// eslint-disable-next-line new-cap
@Module({
  imports: [
    CqrsModule,
    ClientsModule.registerAsync([
      {
        name: UserClient.NAME,
        imports: [MicroServiceConfigModule],
        useFactory: (configService: MicroServiceConfigService) =>
          new RegisterConfig(
            new KafkaClientProviderOptionsFactory(
              configService,
              'user',
              'user-consumer',
            ),
          ).config,
        inject: [MicroServiceConfigService],
      } as ClientsProviderAsyncOptions,
    ]),
  ],
  providers: [...CommandHandlers, ...EventHandlers, UserSaga],
  exports: [CqrsModule],
})
export class UserCqrsModule {}

GitHub Repository

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!