Muti binder customization (#2051)

* Muti binder customization

Enable applications with multi binders to provide customizations for
the binders. This is accomplished by providing a new API called
BinderCustomizer. When an implementation is found for this interface,
the customizations are applied against the binders before providing access to them.

Tests and docs.

Resolves https://github.com/spring-cloud/spring-cloud-stream/issues/1541

* Addressing PR review comments

* Addressing PR review
This commit is contained in:
Soby Chacko
2020-11-18 16:32:05 -05:00
committed by GitHub
parent d574ee15be
commit 442c72b37c
9 changed files with 122 additions and 8 deletions

View File

@@ -1627,6 +1627,38 @@ environment:
profiles:
active: myBinderProfile
----
[[binder-customizer]]
=== Customizing binders in multi binder applications
When an application has multiple binders in it and wants to customize the binders, then that can be achieved by providing a `BinderCustomizer` implementation.
In the case of applications with a single binder, this special customizer is not necessary since the binder context can access the customization beans directly.
However, this is not the case in a multi-binder scenario, since various binders live in different application contexts.
By providing an implementation of `BinderCustomizer` interface, the binders, although reside in different application contexts, will receive the customization.
Spring Cloud Stream ensures that the customizations take place before the applications start using the binders.
The user must check for the binder type and then apply the necessary customizations.
Here is an example of providing a `BinderCustomizer` bean.
```
@Bean
public BinderCustomizer binderCustomizer() {
return (binder, binderName) -> {
if (binder instanceof KafkaMessageChannelBinder) {
((KafkaMessageChannelBinder) binder).setRebalanceListener(...);
}
else if (binder instanceof KStreamBinder) {
...
}
else if (binder instanceof RabbitMessageChannelBinder) {
...
}
};
}
```
Note that, when there are more than one instance of the same type of the binder, the binder name can be used to filter customization.
[[binding_visualization_control]]
=== Binding visualization and control
Since version 2.0, Spring Cloud Stream supports visualization and control of the Bindings through Actuator endpoints.