Skip to content

Commit a6c0a82

Browse files

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/reference/asciidoc/kafka.adoc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,25 +1121,34 @@ Use a custom deserializer, the `JsonDeserializer` or the `(String|Bytes)JsonMess
11211121

11221122
The listener containers created for `@KafkaListener` annotations are not beans in the application context.
11231123
Instead, they are registered with an infrastructure bean of type `KafkaListenerEndpointRegistry`.
1124-
This bean manages the containers' lifecycles; it will auto-start any containers that have `autoStartup` set to `true`.
1124+
This bean is automatically declared by the framework and manages the containers' lifecycles; it will auto-start any containers that have `autoStartup` set to `true`.
11251125
All containers created by all container factories must be in the same `phase` - see <<container-auto-startup>> for more information.
11261126
You can manage the lifecycle programmatically using the registry; starting/stopping the registry will start/stop all the registered containers.
11271127
Or, you can get a reference to an individual container using its `id` attribute; you can set `autoStartup` on the annotation, which will override the default setting configured into the container factory.
1128+
Simply get a reference to the bean from the application context, such as auto wiring, to manage its registered containers:
11281129

1130+
====
1131+
[source, java]
1132+
----
1133+
@KafkaListener(id = "myContainer", topics = "myTopic", autoStartup = "false")
1134+
public void listen(...) { ... }
1135+
1136+
----
1137+
====
1138+
1139+
====
11291140
[source, java]
11301141
----
11311142
@Autowired
11321143
private KafkaListenerEndpointRegistry registry;
11331144
11341145
...
11351146
1136-
@KafkaListener(id = "myContainer", topics = "myTopic", autoStartup = "false")
1137-
public void listen(...) { ... }
1147+
this.registry.getListenerContainer("myContainer").start();
11381148
11391149
...
1140-
1141-
registry.getListenerContainer("myContainer").start();
11421150
----
1151+
====
11431152

11441153
[[kafka-validation]]
11451154
===== @KafkaListener @Payload Validation

0 commit comments

Comments
 (0)