Skip to content

Commit ff2b413

Browse files
garyrussellartembilan
authored andcommitted
GH-756: Doc polishing for the previous commit
1 parent 9c40625 commit ff2b413

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

Diff for: spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListener.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,19 @@
187187
String beanRef() default "__listener";
188188

189189
/**
190-
* Override the container factory's {@code concurrency} setting for this listener.
191-
* May be a property placeholder or SpEL expression that evaluates to an integer.
190+
* Override the container factory's {@code concurrency} setting for this listener. May
191+
* be a property placeholder or SpEL expression that evaluates to a {@link Number}, in
192+
* which case {@link Number#intValue()} is used to obtain the value.
192193
* @return the concurrency.
193194
* @since 2.2
194195
*/
195196
String concurrency() default "";
196197

197198
/**
198-
* Set to true or false, to override the default setting in the container factory.
199+
* Set to true or false, to override the default setting in the container factory. May
200+
* be a property placeholder or SpEL expression that evaluates to a {@link Boolean} or
201+
* a {@link String}, in which case the {@link Boolean#parseBoolean(String)} is used to
202+
* obtain the value.
199203
* @return true to auto start, false to not auto start.
200204
* @since 2.2
201205
*/

Diff for: spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,9 @@ else if (resolved instanceof Number) {
657657
return ((Number) resolved).intValue();
658658
}
659659
else {
660-
throw new IllegalStateException("The [" + attribute + "] must resolve to a String. "
661-
+ "Resolved to [" + resolved.getClass() + "] for [" + value + "]");
660+
throw new IllegalStateException(
661+
"The [" + attribute + "] must resolve to an Number or a String that can be parsed as an Integer. "
662+
+ "Resolved to [" + resolved.getClass() + "] for [" + value + "]");
662663
}
663664
}
664665

@@ -672,8 +673,9 @@ else if (resolved instanceof String) {
672673
return Boolean.parseBoolean(s);
673674
}
674675
else {
675-
throw new IllegalStateException("The [" + attribute + "] must resolve to a Boolean. "
676-
+ "Resolved to [" + resolved.getClass() + "] for [" + value + "]");
676+
throw new IllegalStateException(
677+
"The [" + attribute + "] must resolve to a Boolean or a String that can be parsed as a Boolean. "
678+
+ "Resolved to [" + resolved.getClass() + "] for [" + value + "]");
677679
}
678680
}
679681

Diff for: src/reference/asciidoc/kafka.adoc

+15-1
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,23 @@ public class KafkaConfig {
777777
Notice that to set container properties, you must use the `getContainerProperties()` method on the factory.
778778
It is used as a template for the actual properties injected into the container.
779779

780-
Starting with _version 2.1.1_, it is now possible to set the `client.id` property for consumers created by the annotation.
780+
Starting with version 2.1.1, it is now possible to set the `client.id` property for consumers created by the annotation.
781781
The `clientIdPrefix` is suffixed with `-n` where `n` is an integer representing the container number when using concurrency.
782782

783+
Starting with version 2.2, you can now override the container factory's `concurrency` and `autoStartup` properties using properties on the annotation itself.
784+
The properties can be simple values, property placeholders or SpEL expressions.
785+
786+
====
787+
[source, java]
788+
----
789+
@KafkaListener(id = "myListener", topics = "myTopic",
790+
autoStartup = "${listen.auto.start:true}", concurrency = "${listen.concurrency:3}")
791+
public void listen(String data) {
792+
...
793+
}
794+
----
795+
====
796+
783797
You can also configure POJO listeners with explicit topics and partitions (and, optionally, their initial offsets):
784798

785799
[source, java]

Diff for: src/reference/asciidoc/whats-new.adoc

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ Batch listeners can optionally receive the complete `ConsumerRecords<?, ?>` obje
3131

3232
See <<batch-listeners>> for more information.
3333

34+
==== @KafkaListener Changes
35+
36+
You can now override the `concurrency` and `autoStartup` properties of the listener container factory by setting properties on the annotation.
37+
38+
See <<kafka-listener-annotation>> for more information.
39+
3440
==== Header Mapping Changes
3541

3642
Headers of type `MimeType` and `MediaType` are now mapped as simple strings in the `RecordHeader` value.

0 commit comments

Comments
 (0)