|
23 | 23 | import java.util.Collections;
|
24 | 24 | import java.util.HashMap;
|
25 | 25 | import java.util.List;
|
| 26 | +import java.util.Locale; |
26 | 27 | import java.util.Map;
|
27 | 28 |
|
28 | 29 | import org.apache.kafka.clients.CommonClientConfigs;
|
29 | 30 | import org.apache.kafka.clients.consumer.ConsumerConfig;
|
30 | 31 | import org.apache.kafka.clients.producer.ProducerConfig;
|
31 | 32 | import org.apache.kafka.common.config.SslConfigs;
|
| 33 | +import org.apache.kafka.common.requests.IsolationLevel; |
32 | 34 | import org.apache.kafka.common.serialization.StringDeserializer;
|
33 | 35 | import org.apache.kafka.common.serialization.StringSerializer;
|
34 | 36 |
|
@@ -266,6 +268,11 @@ public static class Consumer {
|
266 | 268 | */
|
267 | 269 | private Duration heartbeatInterval;
|
268 | 270 |
|
| 271 | + /** |
| 272 | + * Isolation level for reading messages that have been written transactionally. |
| 273 | + */ |
| 274 | + private IsolationLevel isolationLevel = IsolationLevel.READ_UNCOMMITTED; |
| 275 | + |
269 | 276 | /**
|
270 | 277 | * Deserializer class for keys.
|
271 | 278 | */
|
@@ -362,6 +369,14 @@ public void setHeartbeatInterval(Duration heartbeatInterval) {
|
362 | 369 | this.heartbeatInterval = heartbeatInterval;
|
363 | 370 | }
|
364 | 371 |
|
| 372 | + public IsolationLevel getIsolationLevel() { |
| 373 | + return this.isolationLevel; |
| 374 | + } |
| 375 | + |
| 376 | + public void setIsolationLevel(IsolationLevel isolationLevel) { |
| 377 | + this.isolationLevel = isolationLevel; |
| 378 | + } |
| 379 | + |
365 | 380 | public Class<?> getKeyDeserializer() {
|
366 | 381 | return this.keyDeserializer;
|
367 | 382 | }
|
@@ -406,6 +421,8 @@ public Map<String, Object> buildProperties() {
|
406 | 421 | map.from(this::getGroupId).to(properties.in(ConsumerConfig.GROUP_ID_CONFIG));
|
407 | 422 | map.from(this::getHeartbeatInterval).asInt(Duration::toMillis)
|
408 | 423 | .to(properties.in(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG));
|
| 424 | + map.from(() -> getIsolationLevel().name().toLowerCase(Locale.ROOT)) |
| 425 | + .to(properties.in(ConsumerConfig.ISOLATION_LEVEL_CONFIG)); |
409 | 426 | map.from(this::getKeyDeserializer).to(properties.in(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG));
|
410 | 427 | map.from(this::getValueDeserializer).to(properties.in(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG));
|
411 | 428 | map.from(this::getMaxPollRecords).to(properties.in(ConsumerConfig.MAX_POLL_RECORDS_CONFIG));
|
|
0 commit comments