Nest.js module for Confluent Schema Registry
npm install nestjs-async-schema-registry``shell`
npm install @goopen/nestjs-schema-registry @kafkajs/confluent-schema-registry
`typescript`
@Module({
imports: [
SchemaRegistryModule.register({
isGlobal: true,
host: SCHEMA_REGISTRY_URL,
auth: {
username: SCHEMA_REGISTRY_USERNAME,
password: SCHEMA_REGISTRY_PASSWORD,
},
}),
],
})
export class KafkaModule {}
Or if you wish to inject the ConfigModule to pull the configuration from environment variables
`typescript``
@Module({
imports: [
ConfigModule.forRoot(),
SchemaRegistryModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
host: configService.get
auth: {
username: configService.get
password: configService.get
},
}),
}),
]
})
export class KafkaModule {}
`typescript``
@Injectable()
export class KafkaService{
constructor(
@InjectSchemaRegistry() private readonly schemaRegistry: SchemaRegistry,
) {}
}