|
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 |
|
@@ -267,11 +269,9 @@ public static class Consumer {
|
267 | 269 | private Duration heartbeatInterval;
|
268 | 270 |
|
269 | 271 | /**
|
270 |
| - * Controls how transactional messages are returned when polling the broker |
271 |
| - * (non-transactional messages will be unconditionally returned, regardless of |
272 |
| - * this setting). |
| 272 | + * Isolation level for reading messages that have been written transactionally. |
273 | 273 | */
|
274 |
| - private String isolationLevel; |
| 274 | + private IsolationLevel isolationLevel = IsolationLevel.READ_UNCOMMITTED; |
275 | 275 |
|
276 | 276 | /**
|
277 | 277 | * Deserializer class for keys.
|
@@ -369,11 +369,11 @@ public void setHeartbeatInterval(Duration heartbeatInterval) {
|
369 | 369 | this.heartbeatInterval = heartbeatInterval;
|
370 | 370 | }
|
371 | 371 |
|
372 |
| - public String getIsolationLevel() { |
| 372 | + public IsolationLevel getIsolationLevel() { |
373 | 373 | return this.isolationLevel;
|
374 | 374 | }
|
375 | 375 |
|
376 |
| - public void setIsolationLevel(String isolationLevel) { |
| 376 | + public void setIsolationLevel(IsolationLevel isolationLevel) { |
377 | 377 | this.isolationLevel = isolationLevel;
|
378 | 378 | }
|
379 | 379 |
|
@@ -421,7 +421,8 @@ public Map<String, Object> buildProperties() {
|
421 | 421 | map.from(this::getGroupId).to(properties.in(ConsumerConfig.GROUP_ID_CONFIG));
|
422 | 422 | map.from(this::getHeartbeatInterval).asInt(Duration::toMillis)
|
423 | 423 | .to(properties.in(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG));
|
424 |
| - map.from(this::getIsolationLevel).to(properties.in(ConsumerConfig.ISOLATION_LEVEL_CONFIG)); |
| 424 | + map.from(() -> getIsolationLevel().name().toLowerCase(Locale.ROOT)) |
| 425 | + .to(properties.in(ConsumerConfig.ISOLATION_LEVEL_CONFIG)); |
425 | 426 | map.from(this::getKeyDeserializer).to(properties.in(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG));
|
426 | 427 | map.from(this::getValueDeserializer).to(properties.in(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG));
|
427 | 428 | map.from(this::getMaxPollRecords).to(properties.in(ConsumerConfig.MAX_POLL_RECORDS_CONFIG));
|
|
0 commit comments