Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the spring.cloud.stream.source really do?

I am trying to understand how the new functional model of Spring Cloud Streams works and how the configuration actually works under the hood.

One of the properties I am unable to figure out is spring.cloud.stream.source.

What does this property actually signify ?

I could not understand the documentation :

Note that preceding example does not have any source functions defined (e.g., Supplier bean) leaving the framework with no trigger to create source bindings, which would be typical for cases where configuration contains function beans. So to trigger the creation of source binding we use spring.cloud.stream.source property where you can declare the name of your sources. The provided name will be used as a trigger to create a source binding.

What if I did not need a Supplier ?

What exactly is a source binding and why is it important ?

What if I only wanted to produce to a messaging topic ? Would I still need this property ?

I also could not understand how it is used in the sample here.

like image 232
ng.newbie Avatar asked Aug 05 '26 00:08

ng.newbie


1 Answers

Spring cloud stream looks for java.util Function<?, ?, Consumer<?>, Supplier<?> beans and creates bindings for them.

In the supplier case, the framework polls the supplier (each second by default) and sends the resulting data.

For example

@Bean
public Supplier<String> output() {
    return () -> "foo";
}
spring.cloud.stream.bindings.output-out-0.destination=bar

will send foo to destination bar each second.

But, what if you don't need a polled source, but you want to configure a binding to which you can send arbitrary data. Enter spring.cloud.stream.source.

spring.cloud.stream.source=output
spring.cloud.stream.bindings.output-out-0.destination=bar

allows you to send arbitrary data to the stream bridge

bridge.send("output-out-0", "test");

In other words, it allows you to configure one or more ouput bindings that you can use in the StreamBridge; otherwise, when you send to the bridge, the binding is created dynamically.

like image 175
Gary Russell Avatar answered Aug 07 '26 14:08

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!