英文:
Fetch data on nestjs module before initialating it
问题
以下是翻译好的部分:
"so I'm trying to create a kafka client and my credentials are on aws KMS, so i need to fetch my sasl username and password before starting my module."
因此,我正在尝试创建一个 Kafka 客户端,我的凭据存储在 AWS KMS 上,所以我需要在启动模块之前获取我的 SASL 用户名和密码。
"Does anyone know how to fetch data on a module first? Thanks"
有人知道如何首先在模块中获取数据吗?谢谢。
"Since this is executed right after a nest run, i cant use an await to first load this on my dotenv and then access it, so i need an async way"
由于这是在 nest 运行之后立即执行的,我无法使用 await 先加载它到我的 dotenv,然后访问它,所以我需要一种异步的方法。
英文:
so I'm trying to create a kafka client and my credentials are on aws KMS, so i need to fetch my sasl username and password before starting my module.
Does anyone know how to fetch data on a module fisrt? Thanks
@Module({
imports: [
ConfigModule
ClientsModule.register([
{
name: 'producer',
transport: Transport.KAFKA,
options: {
client: {
clientId: 'messages',
brokers: [...BROKERS.split(',')],
ssl: {
rejectUnauthorized: false,
},
sasl: {
mechanism: 'scram-sha-512',
username, // This is what i want to fetch
password, // This is what i want to fetch
},
},
consumer: {
groupId: 'client',
sessionTimeout: 60000,
minBytes: 5,
maxBytes: 40000000,
},
},
},
]),
],
controllers: [ProducerController],
providers: [ProducerService],
})
export class ProducerModule {}
Since this is executed right after a nest run, i cant use an await to first load this on my dotenv and then access it, so i need an asnync way
答案1
得分: 0
好的!我做好了,所以你可以在模块中使用异步函数!
@Module({
imports: [yourFunction()], // 创建了一个异步函数并可以使用!
controllers: [ProducerController],
providers: [ProducerService],
})
export class ProducerModule {}
英文:
Okay! I made it, so you can use an async function in the module!
@Module({
imports: [yourFunction()], // Made an async func and works!
controllers: [ProducerController],
providers: [ProducerService],
})
export class ProducerModule {}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论