Multiline values in application.yml for spring.cloud.function.definition

Viewed 159

We have a Spring boot project using the deprecated @StreamListener and now we are switching to Spring Cloud Stream functional kafka binders.

The problem is that this service connects to multiple kafka topics and our single line spring.cloud.function.definition: topicA;topicB;topicC;...;topicN is becoming very long

I would like to know how to use on Spring's application.yaml the yaml capabilities such as multi line values (such as | or > operators) but I haven't found something similar on documentation.

My goal would be something such as

spring.cloud.function.definition: | topicA;
                                    topicB;
                                    topicC;
                                    ...;
                                    topicN

Thanks

1 Answers

There are multiple ways to represent multiline values in YAML. Details could be found in How do I break a string in YAML over multiple lines? and most of them are supported in Spring and could be used in application.yml.

Using multiline for auction definitions in Spring Cloud Stream

All above approaches works in Spring but at the end it really depends how the result value is used. In some cases new line character is preserved and in some cases replaced with space.

From what I see spring.cloud.function.definition is parsed in org.springframework.cloud.stream.function.FunctionConfiguration and logic doesn't expect any white spaces.

The only approach that would work in this case is double-quoted block with escaped the newline

spring.cloud.function.definition: "topicA;topicB;topicC;\
  ...;topicN"
Related