17
17
package org .springframework .boot .autoconfigure .kafka ;
18
18
19
19
import java .io .IOException ;
20
- import java .math .BigDecimal ;
21
20
import java .time .Duration ;
22
21
import java .time .temporal .ChronoUnit ;
23
22
import java .util .ArrayList ;
42
41
import org .springframework .core .io .Resource ;
43
42
import org .springframework .kafka .listener .ContainerProperties .AckMode ;
44
43
import org .springframework .kafka .security .jaas .KafkaJaasLoginModuleInitializer ;
45
- import org .springframework .util .Assert ;
46
44
import org .springframework .util .CollectionUtils ;
47
45
import org .springframework .util .unit .DataSize ;
48
46
@@ -1341,96 +1339,105 @@ public void setOptions(Map<String, String> options) {
1341
1339
1342
1340
}
1343
1341
1344
- public static class Retry {
1342
+ public static class Security {
1345
1343
1346
- private Topic topic = new Topic ();
1344
+ /**
1345
+ * Security protocol used to communicate with brokers.
1346
+ */
1347
+ private String protocol ;
1347
1348
1348
- public Topic getTopic () {
1349
- return this .topic .validate ();
1349
+ public String getProtocol () {
1350
+ return this .protocol ;
1351
+ }
1352
+
1353
+ public void setProtocol (String protocol ) {
1354
+ this .protocol = protocol ;
1355
+ }
1356
+
1357
+ public Map <String , Object > buildProperties () {
1358
+ Properties properties = new Properties ();
1359
+ PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
1360
+ map .from (this ::getProtocol ).to (properties .in (CommonClientConfigs .SECURITY_PROTOCOL_CONFIG ));
1361
+ return properties ;
1350
1362
}
1351
1363
1352
- public void setTopic (Topic topic ) {
1353
- this .topic = topic ;
1364
+ }
1365
+
1366
+ public static class Retry {
1367
+
1368
+ private final Topic topic = new Topic ();
1369
+
1370
+ public Topic getTopic () {
1371
+ return this .topic ;
1354
1372
}
1355
1373
1356
1374
/**
1357
1375
* Properties for non-blocking, topic-based retries.
1358
1376
*/
1359
1377
public static class Topic {
1360
1378
1361
- private static final String RETRY_TOPIC_PROPERTIES_PREFIX = "spring.kafka.retry.topic." ;
1362
-
1363
- private static final String RETRY_TOPIC_VALIDATION_ERROR_MSG = "Property " + RETRY_TOPIC_PROPERTIES_PREFIX
1364
- + "%s should be greater than or equal to %s. Provided value was %s." ;
1365
-
1366
1379
/**
1367
- * Whether to enable topic-based retries auto-configuration .
1380
+ * Whether to enable topic-based non-blocking retries .
1368
1381
*/
1369
- private Boolean enabled ;
1382
+ private boolean enabled ;
1370
1383
1371
1384
/**
1372
- * The total number of processing attempts made before sending the message to
1373
- * the DLT.
1385
+ * Total number of processing attempts made before sending the message to the
1386
+ * DLT.
1374
1387
*/
1375
- private Integer attempts = 3 ;
1388
+ private int attempts = 3 ;
1376
1389
1377
1390
/**
1378
- * A canonical backoff period. Used as an initial value in the exponential
1379
- * case, and as a minimum value in the uniform case.
1391
+ * Canonical backoff period. Used as an initial value in the exponential case,
1392
+ * and as a minimum value in the uniform case.
1380
1393
*/
1381
1394
private Duration delay = Duration .ofSeconds (1 );
1382
1395
1383
1396
/**
1384
- * If positive, then used as a multiplier for generating the next delay for
1385
- * backoff.
1397
+ * Multiplier to use for generating the next backoff delay.
1386
1398
*/
1387
- private Double multiplier = 0.0 ;
1399
+ private double multiplier = 0.0 ;
1388
1400
1389
1401
/**
1390
- * The maximum wait between retries. If less than the delay then the default
1391
- * of 30 seconds is applied.
1402
+ * Maximum wait between retries. If less than the delay then the default of 30
1403
+ * seconds is applied.
1392
1404
*/
1393
1405
private Duration maxDelay = Duration .ZERO ;
1394
1406
1395
1407
/**
1396
- * In the exponential case, set this to true to have the backoff delays
1397
- * randomized.
1408
+ * Whether to have the backoff delays.
1398
1409
*/
1399
- private Boolean randomBackOff = false ;
1410
+ private boolean randomBackOff = false ;
1400
1411
1401
- public Boolean getEnabled () {
1412
+ public boolean isEnabled () {
1402
1413
return this .enabled ;
1403
1414
}
1404
1415
1405
- public void setEnabled (Boolean enabled ) {
1416
+ public void setEnabled (boolean enabled ) {
1406
1417
this .enabled = enabled ;
1407
1418
}
1408
1419
1409
- public Integer getAttempts () {
1420
+ public int getAttempts () {
1410
1421
return this .attempts ;
1411
1422
}
1412
1423
1413
- public void setAttempts (Integer attempts ) {
1424
+ public void setAttempts (int attempts ) {
1414
1425
this .attempts = attempts ;
1415
1426
}
1416
1427
1417
1428
public Duration getDelay () {
1418
1429
return this .delay ;
1419
1430
}
1420
1431
1421
- public Long getDelayMillis () {
1422
- return (this .delay != null ) ? this .delay .toMillis () : null ;
1423
- }
1424
-
1425
1432
public void setDelay (Duration delay ) {
1426
1433
this .delay = delay ;
1427
1434
}
1428
1435
1429
- public Double getMultiplier () {
1436
+ public double getMultiplier () {
1430
1437
return this .multiplier ;
1431
1438
}
1432
1439
1433
- public void setMultiplier (Double multiplier ) {
1440
+ public void setMultiplier (double multiplier ) {
1434
1441
this .multiplier = multiplier ;
1435
1442
}
1436
1443
@@ -1442,59 +1449,14 @@ public void setMaxDelay(Duration maxDelay) {
1442
1449
this .maxDelay = maxDelay ;
1443
1450
}
1444
1451
1445
- public Long getMaxDelayMillis () {
1446
- return (this .maxDelay != null ) ? this .maxDelay .toMillis () : null ;
1447
- }
1448
-
1449
- public Boolean isRandomBackOff () {
1452
+ public boolean isRandomBackOff () {
1450
1453
return this .randomBackOff ;
1451
1454
}
1452
1455
1453
- public void setRandomBackOff (Boolean randomBackOff ) {
1456
+ public void setRandomBackOff (boolean randomBackOff ) {
1454
1457
this .randomBackOff = randomBackOff ;
1455
1458
}
1456
1459
1457
- private Topic validate () {
1458
- validateProperty ("attempts" , this .attempts , 1 );
1459
- validateProperty ("delay" , this .getDelayMillis (), 0 );
1460
- validateProperty ("multiplier" , this .multiplier , 0 );
1461
- validateProperty ("maxDelay" , this .getMaxDelayMillis (), 0 );
1462
- Assert .isTrue (this .multiplier != 0 || !this .isRandomBackOff (),
1463
- "Property " + RETRY_TOPIC_PROPERTIES_PREFIX
1464
- + "randomBackOff should not be true with non-exponential back offs." );
1465
- return this ;
1466
- }
1467
-
1468
- private static void validateProperty (String propertyName , Number providedValue , int minValue ) {
1469
- Assert .notNull (providedValue , () -> RETRY_TOPIC_PROPERTIES_PREFIX + propertyName + " cannot be null." );
1470
- Assert .isTrue (new BigDecimal (providedValue .toString ()).compareTo (BigDecimal .valueOf (minValue )) >= 0 ,
1471
- () -> String .format (RETRY_TOPIC_VALIDATION_ERROR_MSG , propertyName , minValue , providedValue ));
1472
- }
1473
-
1474
- }
1475
-
1476
- }
1477
-
1478
- public static class Security {
1479
-
1480
- /**
1481
- * Security protocol used to communicate with brokers.
1482
- */
1483
- private String protocol ;
1484
-
1485
- public String getProtocol () {
1486
- return this .protocol ;
1487
- }
1488
-
1489
- public void setProtocol (String protocol ) {
1490
- this .protocol = protocol ;
1491
- }
1492
-
1493
- public Map <String , Object > buildProperties () {
1494
- Properties properties = new Properties ();
1495
- PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
1496
- map .from (this ::getProtocol ).to (properties .in (CommonClientConfigs .SECURITY_PROTOCOL_CONFIG ));
1497
- return properties ;
1498
1460
}
1499
1461
1500
1462
}
0 commit comments