1

I'm trying to use env var to configure a kafka on seedstack. The syntax works with mongoDB configuration but not with kafka configuration.

here's my mongo conf:

env:
  MONGO_URL: "localhost:27017"
  MONGO_CREDENTIAL: ""

mongoDb:
  clients:
    mongoClient:
      databases: mongoDB
      uri: mongodb://${env.MONGO_CREDENTIAL}${env.MONGO_URL}

here's my mongo kafka

env:
  MONGO_URL: "localhost:27017"
  MONGO_CREDENTIAL: ""

kafka:
  consumers:
    consumer1:
      topics: [topic1]
      properties:
        bootstrap.servers: ${env.KAFKA_URL}
        key.deserializer: org.apache.kafka.common.serialization.StringDeserializer
        value.deserializer: org.apache.kafka.connect.json.JsonDeserializer
        auto.offset.reset: earliest

It's seems that the environment var substitution is not working for va under properties:.

Any ideas about how making this working ?

Lautre
  • 155
  • 1
  • 3
  • 12

1 Answers1

2

After testing this case, I found that the properties mapper didn't properly invoked the value evaluators. As a result the macro was not evaluated.

I released version 3.1.4 of the configuration library that fixes the problem. It will be included in a future version of SeedStack but you can benefit from it now by adding this dependency management in your pom.xml, AFTER the seedstack-bom import:

<dependencyManagement>
    <dependencies>

        <!-- seedstack-bom import is here -->

        <dependency>
            <groupId>org.seedstack.coffig</groupId>
            <artifactId>coffig</artifactId>
            <version>3.1.4</version>
        </dependency>
    </dependencies>
</dependencyManagement>

As a side note, I suggest that you don't define anything in the env subtree manually but use the macro fallback mechanism instead:

${env.SOME_VAR:'defaultValue'}

Note that you can cascade the fallback:

${env.SOME_VAR:sys.someSystemProperty:'defaultValue'}

You need to quote the literal default value to avoid it being resolved as a config node.

Adrien LAUER
  • 444
  • 2
  • 7