Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load producer / consumer config from properties file #4

Closed
gAmUssA opened this issue Aug 3, 2020 · 1 comment
Closed

load producer / consumer config from properties file #4

gAmUssA opened this issue Aug 3, 2020 · 1 comment

Comments

@gAmUssA
Copy link

gAmUssA commented Aug 3, 2020

@fhussonnois
Copy link
Member

fhussonnois commented Aug 5, 2020

Hi @gAmUssA, thank you for the issue. Since I was working on refactoring the configuration classes KafkaConsumerConfigs, KafkaProducerConfigs (which now implement MutableMap), I've added Kotlin extensions to easily load config from properties file.

Some examples showing how to load config file :

   // Example 1 -> KafkaConsumerConfigs can be directly used to create a new KafkaConsumer
    KafkaConsumer<String, String>(KafkaConsumerConfigs()
        .load("/tmp/config.properties")
        .keyDeserializer(StringDeserializer::class.java.name)
        .valueDeserializer(StringDeserializer::class.java.name)
    ).use {
        // do something useful
    }
    // Example 2 -> using convenient function
    // i.e : one of : loadClientConfigs, loadConsumerConfig, loadProducerConfigs
    val configs: KafkaProducerConfigs = loadProducerConfigs("/tmp/config.properties")
    // Example 3 -> also work with KafkaClients DSL
    kafka(loadClientConfigs("/tmp/config.properties")) {
        client {
            clientId("demo-client")
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants