Closed demetris-manikas closed 3 weeks ago
In order to configure the kafka from dbos-config env I did the following (copy/paste from knexfile.js)
knexfile.js
import { KafkaConfig, KafkaMessage} from "kafkajs"; import { Workflow, WorkflowContext, Kafka, KafkaConsume } from '@dbos-inc/dbos-sdk'; import { parseConfigFile } from '@dbos-inc/dbos-sdk/dist/src/dbos-runtime/config'; const [config, ] = parseConfigFile() export const brokers = (config.env?.kafka_brokers ?? '').split(',').map(r => r.trim()); export const clientId = config.env?.kafka_clientId ?? ''; export const topic = config.env?.kafka_topic ?? ''; const kafkaConfig: KafkaConfig = { brokers: brokers, clientId: clientId, }; @Kafka(kafkaConfig) export class KafkaConsumer { @KafkaConsume(topic) @Workflow() static async kafkaConsumeWorkflow(ctxt: WorkflowContext, topic: string, partition: number, message: KafkaMessage) { ctxt.logger.info(`Message received: ${message.value?.toString()}`); return Promise.resolve(); } }
I would expect the env variables to be present in process.env or be accessible via a library call. I would a lot rather
process.env
import { ENV } from '@dbos-inc/dbos-sdk'
or
export const topic = process.env.kafka_topic ?? '';
and go from there than having to
import { parseConfigFile } from '@dbos-inc/dbos-sdk/dist/src/dbos-runtime/config'; const [config, ] = parseConfigFile()
every time I need to access an env variable.
Is there a better way to do this?
Thanks.
Well... Sorry. Mabe a typo made me think that env is not in process.env but it is.
closing
In order to configure the kafka from dbos-config env I did the following (copy/paste from
knexfile.js
)I would expect the env variables to be present in
process.env
or be accessible via a library call. I would a lot ratheror
and go from there than having to
every time I need to access an env variable.
Is there a better way to do this?
Thanks.