0
votes

Generally, we provide the Spring Cloud Stream Kafka configurations like the binder, consumer, producer configurations in application.yaml or application.properties.

I am looking for a way to configure it using pure JavaBean configuration.

I am specifically looking to Spring Cloud Stream Kafka configurations to Java based configurations like:

spring.cloud.stream.kafka.binder.configuration.security.protocol=SASL_SSL

Can someone provide a suggestion or offer a solution to this problem?

1
May you share with us a requirement to do that? Typically a configuration is separated from the application and can come from many places. See 12-factors applications. I don’t tell that it is possible to create beans on the matter with hard coded values, but that is going to be a bit awkward for Microservices architecture... - Artem Bilan
We want to externalize not all but few configurations e.g. spring.cloud.kafka.binder.broker, bindings.destinations or truststore.locations to set it from an environment variable or externalized service(e.g. vcapservice). Hence, we think to have some of these configurations set as java configurations and loading it will be the good option. - Tech_Forum

1 Answers

0
votes

One of the solution can be done via packaging an application.properties into a jar of your application. Another one can be done via an EnvironmentPostProcessor implementation.

And also you can create a BindingServiceProperties bean with the @Primary based on the BindingServiceProperties populated by the framework:

    @Bean
    @Primary
    public BindingServiceProperties bindingServiceProperties(
            BindingServiceProperties properties) {

And remap the properties you can provide in the external resource having the rest hard-coded here in this bean definition.