Skip to content

Commit 2960df4

Browse files
committed
GH-3166 Deprecate defineInput/OutputBinding
Add documentation for create input and output binding
1 parent fce0d43 commit 2960df4

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindingsLifecycleController.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,20 @@ public BindingsLifecycleController(List<InputBindingLifecycle> inputBindingLifec
9595

9696
/**
9797
* Allows to dynamically create a new input binding returning its consumer properties for further customization.
98-
* Unlike {@link #defineBinding(BindableFunctionProxyFactory)} this method will not initialize the binding.
99-
* You have to call {@link #defineBinding(BindableFunctionProxyFactory)} explicitly after you create a binding.
10098
* @param <P> the type of consumer properties. For example, if binding derives from Kafka, it will return KafkaConsumerProperties.
10199
* @param bindingName the name of the binding.
102100
* @param binderName the name of the binder.
103101
* @param bindingProperties instance of BindingProperties.
104102
* @return instance of the consumer properties.
105103
*/
106-
@SuppressWarnings("unchecked")
107104
public <P> P createInputBinding(String bindingName, String binderName, BindingProperties bindingProperties) {
108105
Assert.hasText(bindingProperties.getGroup(), "Anonymous bindings are not allowed for explicit creation. You must define 'group'");
109106
DefaultBinderFactory binderFactory = this.applicationContext.getBean(DefaultBinderFactory.class);
110107
Object binder = binderFactory.getBinder(binderName, MessageChannel.class);
111108
BindingServiceProperties bindingServiceProperties = this.applicationContext.getBean(BindingServiceProperties.class);
112109
bindingServiceProperties.setBindings(Collections.singletonMap(bindingName, bindingProperties));
113-
if (binder instanceof ExtendedPropertiesBinder extendedPropertiesBinder) {
114-
Object extensionPropertries = extendedPropertiesBinder.getExtendedConsumerProperties(bindingName);
115-
return (P) extensionPropertries;
110+
if (binder instanceof ExtendedPropertiesBinder) {
111+
return this.defineInputBinding(bindingName);
116112
}
117113
else {
118114
throw new IllegalStateException("Binder must be an instance of ExtendedPropertiesBinder");
@@ -121,23 +117,19 @@ public <P> P createInputBinding(String bindingName, String binderName, BindingPr
121117

122118
/**
123119
* Allows to dynamically create a new input binding returning its consumer properties for further customization.
124-
* Unlike {@link #defineBinding(BindableFunctionProxyFactory)} this method will not initialize the binding.
125-
* You have to call {@link #defineBinding(BindableFunctionProxyFactory)} explicitly after you create a binding.
126120
* @param <P> the type of consumer properties. For example, if binding derives from Kafka, it will return KafkaConsumerProperties.
127121
* @param bindingName the name of the binding.
128122
* @param binderName the name of the binder.
129123
* @param bindingProperties instance of BindingProperties.
130124
* @return instance of the consumer properties.
131125
*/
132-
@SuppressWarnings("unchecked")
133126
public <P> P createOutputBinding(String bindingName, String binderName, BindingProperties bindingProperties) {
134127
DefaultBinderFactory binderFactory = this.applicationContext.getBean(DefaultBinderFactory.class);
135128
Object binder = binderFactory.getBinder(binderName, MessageChannel.class);
136129
BindingServiceProperties bindingServiceProperties = this.applicationContext.getBean(BindingServiceProperties.class);
137130
bindingServiceProperties.setBindings(Collections.singletonMap(bindingName, bindingProperties));
138-
if (binder instanceof ExtendedPropertiesBinder extendedPropertiesBinder) {
139-
Object extensionPropertries = extendedPropertiesBinder.getExtendedProducerProperties(bindingName);
140-
return (P) extensionPropertries;
131+
if (binder instanceof ExtendedPropertiesBinder) {
132+
return this.defineOutputBinding(bindingName);
141133
}
142134
else {
143135
throw new IllegalStateException("Binder must be an instance of ExtendedPropertiesBinder");
@@ -149,7 +141,9 @@ public <P> P createOutputBinding(String bindingName, String binderName, BindingP
149141
* @param <P> the type of consumer properties. For example, if binding derives from Kafka, it will return KafkaConsumerProperties.
150142
* @param bindingName the name of the binding.
151143
* @return instance of the consumer properties.
144+
* @deprecated since 5.0.2
152145
*/
146+
@Deprecated
153147
public <P> P defineInputBinding(String bindingName) {
154148
BindableFunctionProxyFactory bindingProxyFactory =
155149
new BindableFunctionProxyFactory(bindingName, 1, 0, this.applicationContext.getBean(StreamFunctionProperties.class), false);
@@ -162,7 +156,9 @@ public <P> P defineInputBinding(String bindingName) {
162156
* @param <P> the type of producer properties. For example, if binding derives from Kafka, it will return KafkaProducerProperties.
163157
* @param bindingName the name of the binding.
164158
* @return instance of the producer properties.
159+
* @deprecated since 5.0.2
165160
*/
161+
@Deprecated
166162
public <P> P defineOutputBinding(String bindingName) {
167163
BindableFunctionProxyFactory bindingProxyFactory =
168164
new BindableFunctionProxyFactory(bindingName, 0, 1, this.applicationContext.getBean(StreamFunctionProperties.class), false);

docs/modules/ROOT/pages/spring-cloud-stream/binding_visualization_control.adoc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,24 @@ its Consumer and Producer configuration properties for more dynamic management o
3030

3131
For example.
3232

33-
To define new input binding you can call `BindingsLifecycleController.defineInputBinding(..)` method (see below). There is equivalent of `defineOutputBinding(..)` method.
33+
To define new input binding you can call `BindingsLifecycleController.createInputBinding(..)` method (see below). There is equivalent of `createOutputBinding(..)` method.
3434

3535
[source,java]
3636
----
37+
DefaultBinderFactory binderFactory = context.getBean(DefaultBinderFactory.class);
38+
Object binder = binderFactory.getBinder("rabbit", MessageChannel.class);
39+
40+
String inputName = "test-output-binding";
41+
3742
BindingsLifecycleController controller = context.getBean(BindingsLifecycleController.class);
38-
KafkaConsumerProperties consumerProperties = controller.defineInputBinding("test-input-binding");
43+
44+
BindingProperties bindingProperties = new BindingProperties();
45+
bindingProperties.setDestination("myDest");
46+
bindingProperties.setGroup("myGroup"); // must define group for input binding
47+
ConsumerProperties consumerProperties = new ConsumerProperties();
48+
bindingProperties.setConsumer(consumerProperties);
49+
50+
RabbitConsumerProperties extendedConsumerProperties = controller.createInputBinding(inputName, "rabbit", bindingProperties);
3951
----
4052

4153
You can than manage its properties by calling `getExtensionProperties(..)` method.

0 commit comments

Comments
 (0)