Commit 85cd556
authored
Add concurrency support to
Share consumers (KIP-932) enable record-level load balancing where
multiple consumers can cooperatively process from the same partitions.
Unlike traditional consumer groups with exclusive partition ownership,
share groups distribute work at the broker level via the share group
coordinator.
This commit adds native concurrency support to the existing
`ShareKafkaMessageListenerContainer` rather than creating a separate
`ConcurrentShareKafkaMessageListenerContainer`. This design choice
avoids the parent/child container complexity that exists in the regular
consumer model, since share consumers fundamentally operate differently:
- Work distribution happens at the broker level, not at the Spring layer
- Multiple threads simply provide more capacity for the broker to
distribute records across
- No partition ownership model to coordinate between child containers
This approach provides:
- Simpler architecture with a single container managing multiple threads
- No parent/child context propagation concerns
- Better alignment with share consumer semantics (record-level vs
partition-level distribution)
- Increased throughput for high-volume workloads
- Better resource utilization across consumer threads
Users can configure concurrency at three levels:
1. Per-listener via `@KafkaListener(concurrency = N)`
2. Factory-level default via `factory.setConcurrency(N)`
3. Programmatically via `container.setConcurrency(N)`
The feature works seamlessly with both implicit (auto-acknowledge) and
explicit (manual acknowledge/release/reject) acknowledgment modes, with
each consumer thread independently managing its own acknowledgments.
* Address PR feedback on concurrency implementation
- Use primitive int for concurrency in factory (consistent with phase field)
- Remove unnecessary `getConcurrency()` getter (only used in trivial tests)
- Use `HashMap` instead of `ConcurrentHashMap` in metrics() (already inside lock)
- Use `CompletableFuture.allOf()` for cleaner shutdown coordination
- Remove debug logging from tests (unnecessary noise in CI/CD)
- Remove thread tracking from concurrency tests (over-complicates assertions)
Clarify documentation based on KIP-932 specifications:
- Add explicit note that concurrency is additive across application instances
- Replace high-level distribution description with precise KIP-932 details
- Document pull-based model, acquisition locks, and batch behavior
- Explain `max.poll.records` as soft limit with complete batch preference
- Set accurate expectations about broker-controlled record distribution
Signed-off-by: Soby Chacko <[email protected]>ShareKafkaMessageListenerContainer
1 parent 1972769 commit 85cd556
File tree
5 files changed
+551
-24
lines changed- spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka
- spring-kafka/src
- main/java/org/springframework/kafka
- config
- listener
- test/java/org/springframework/kafka/listener
5 files changed
+551
-24
lines changedLines changed: 168 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
154 | 320 | | |
155 | 321 | | |
156 | 322 | | |
| |||
520 | 686 | | |
521 | 687 | | |
522 | 688 | | |
523 | | - | |
524 | 689 | | |
525 | 690 | | |
526 | | - | |
| 691 | + | |
527 | 692 | | |
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
98 | 100 | | |
99 | 101 | | |
100 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
101 | 119 | | |
102 | 120 | | |
103 | 121 | | |
| |||
138 | 156 | | |
139 | 157 | | |
140 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
141 | 168 | | |
142 | 169 | | |
143 | 170 | | |
| |||
0 commit comments