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

[feature request] convenience function for creating settings fully from properties #197

Open
lsafer-meemer opened this issue Jul 1, 2024 · 1 comment

Comments

@lsafer-meemer
Copy link

lsafer-meemer commented Jul 1, 2024

Sometimes settings are given as Properties.
Having to read, decode and pass individual parameters to the any Settings class is too much work.

My request is to add a function for each Settings class that has a single Properties parameters and get
the required Settings parameters from that single Properties parameter and if any required parameter
is missing or invalid, throws an IllegalArgumentException

Here is the functions I'm proposing:

fun createAdminSettings(
    properties: Properties
): AdminSettings {
    val bootstrapServers = properties.getProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG)

    return AdminSettings(
        bootstrapServer = bootstrapServers,
        props = properties,
    )
}

fun <K, V> createReceiverSettings(
    properties: Properties,
    keyDeserializer: Deserializer<K>,
    valueDeserializer: Deserializer<V>,
): ReceiverSettings<K, V> {
    val bootstrapServers = properties.getProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG)
    val groupId = properties.getProperty(ConsumerConfig.GROUP_ID_CONFIG)

    return ReceiverSettings(
        bootstrapServers = bootstrapServers,
        keyDeserializer = keyDeserializer,
        valueDeserializer = valueDeserializer,
        groupId = groupId,
        properties = properties
    )
}

fun <K, V> createPublisherSettings(
    properties: Properties,
    keySerializer: Serializer<K>,
    valueSerializer: Serializer<V>,
): PublisherSettings<K, V> {
    val bootstrapServers = properties.getProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG)

    return PublisherSettings(
        bootstrapServers = bootstrapServers,
        keySerializer = keySerializer,
        valueSerializer = valueSerializer,
    )
}

why the create prefix? to make it more obvious that this is a convenience function and not a constructor.
Thus, implies that providing properties alone does not satisfies all the requirements of creating an instance
of the class but extra implicit steps will be done to actually create the class.

@nomisRev
Copy link
Owner

nomisRev commented Jul 2, 2024

Hey @lsafer-meemer,

Great request, I've been thinking about this a lot as well. I think would be gerat to have this kind-of utility!

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