Spring Cloud Stream creates default bindings based on the function definition and signature, but how do I override these to more domain friendly names?
Assume that following is your function signature.
@Bean
public Function<String, String> uppercase(){
...
}
By default, Spring Cloud Stream will create the bindings as below.
-
uppercase-in-0
-
uppercase-out-0
You can override these bindings to something by using the following properties.
spring.cloud.stream.function.bindings.uppercase-in-0=my-transformer-in
spring.cloud.stream.function.bindings.uppercase-out-0=my-transformer-out
After this, all binding properties must be made on the new names, my-transformer-in
and my-transformer-out
.
Here is another example with Kafka Streams and multiple inputs.
@Bean
public BiFunction<KStream<String, Order>, KTable<String, Account>, KStream<String, EnrichedOrder>> processOrder() {
...
}
By default, Spring Cloud Stream will create three different binding names for this function.
-
processOrder-in-0
-
processOrder-in-1
-
processOrder-out-0
You have to use these binding names each time you want to set some configuration on these bindings. You don’t like that, and you want to use more domain-friendly and readable binding names, for example, something like.
-
orders
-
accounts
-
enrichedOrders
You can easily do that by simply setting these three properties
-
spring.cloud.stream.function.bindings.processOrder-in-0=orders
-
spring.cloud.stream.function.bindings.processOrder-in-1=accounts
-
spring.cloud.stream.function.bindings.processOrder-out-0=enrichedOrders
Once you do that, it overrides the default binding names and any properties that you want to set on them must be on these new binding names.