@@ -84,13 +84,13 @@ public class VerifiableShareConsumer implements Closeable, AcknowledgementCommit
84
84
private final ObjectMapper mapper = new ObjectMapper ();
85
85
private final PrintStream out ;
86
86
private final KafkaShareConsumer <String , String > consumer ;
87
+ private final Admin adminClient ;
87
88
private final String topic ;
88
89
private final AcknowledgementMode acknowledgementMode ;
89
90
private final String offsetResetStrategy ;
90
91
private final Boolean verbose ;
91
92
private final int maxMessages ;
92
93
private Integer totalAcknowledged = 0 ;
93
- private final String brokerHostandPort ;
94
94
private final String groupId ;
95
95
private final CountDownLatch shutdownLatch = new CountDownLatch (1 );
96
96
@@ -317,22 +317,22 @@ public long offset() {
317
317
}
318
318
319
319
public VerifiableShareConsumer (KafkaShareConsumer <String , String > consumer ,
320
+ Admin adminClient ,
320
321
PrintStream out ,
321
322
Integer maxMessages ,
322
323
String topic ,
323
324
AcknowledgementMode acknowledgementMode ,
324
325
String offsetResetStrategy ,
325
- String brokerHostandPort ,
326
326
String groupId ,
327
327
Boolean verbose ) {
328
328
this .out = out ;
329
329
this .consumer = consumer ;
330
+ this .adminClient = adminClient ;
330
331
this .topic = topic ;
331
332
this .acknowledgementMode = acknowledgementMode ;
332
333
this .offsetResetStrategy = offsetResetStrategy ;
333
334
this .verbose = verbose ;
334
335
this .maxMessages = maxMessages ;
335
- this .brokerHostandPort = brokerHostandPort ;
336
336
this .groupId = groupId ;
337
337
addKafkaSerializerModule ();
338
338
}
@@ -407,11 +407,6 @@ public void run() {
407
407
ShareGroupAutoOffsetResetStrategy offsetResetStrategy =
408
408
ShareGroupAutoOffsetResetStrategy .fromString (this .offsetResetStrategy );
409
409
410
- Properties adminClientProps = new Properties ();
411
- adminClientProps .put (CommonClientConfigs .BOOTSTRAP_SERVERS_CONFIG , brokerHostandPort );
412
-
413
- Admin adminClient = Admin .create (adminClientProps );
414
-
415
410
ConfigResource configResource = new ConfigResource (ConfigResource .Type .GROUP , groupId );
416
411
Map <ConfigResource , Collection <AlterConfigOp >> alterEntries = new HashMap <>();
417
412
alterEntries .put (configResource , List .of (new AlterConfigOp (new ConfigEntry (
@@ -555,12 +550,13 @@ private static ArgumentParser argParser() {
555
550
.dest ("offsetResetStrategy" )
556
551
.help ("Set share group reset strategy (must be either 'earliest' or 'latest')" );
557
552
558
- parser .addArgument ("--consumer. config" )
553
+ parser .addArgument ("--command- config" )
559
554
.action (store ())
560
555
.required (false )
561
556
.type (String .class )
557
+ .dest ("commandConfig" )
562
558
.metavar ("CONFIG_FILE" )
563
- .help ("Consumer config properties file (config options shared with command line parameters will be overridden)." );
559
+ .help ("Config properties file (config options shared with command line parameters will be overridden)." );
564
560
565
561
return parser ;
566
562
}
@@ -571,8 +567,8 @@ public static VerifiableShareConsumer createFromArgs(ArgumentParser parser, Stri
571
567
AcknowledgementMode acknowledgementMode =
572
568
AcknowledgementMode .valueOf (res .getString ("acknowledgementMode" ).toUpperCase (Locale .ROOT ));
573
569
String offsetResetStrategy = res .getString ("offsetResetStrategy" ).toLowerCase (Locale .ROOT );
574
- String configFile = res .getString ("consumer.config " );
575
- String brokerHostandPort = res .getString ("bootstrapServer" );
570
+ String configFile = res .getString ("commandConfig " );
571
+ String brokerHostAndPort = res .getString ("bootstrapServer" );
576
572
577
573
Properties consumerProps = new Properties ();
578
574
if (configFile != null ) {
@@ -587,7 +583,7 @@ public static VerifiableShareConsumer createFromArgs(ArgumentParser parser, Stri
587
583
588
584
consumerProps .put (ConsumerConfig .GROUP_ID_CONFIG , groupId );
589
585
590
- consumerProps .put (ConsumerConfig .BOOTSTRAP_SERVERS_CONFIG , brokerHostandPort );
586
+ consumerProps .put (ConsumerConfig .BOOTSTRAP_SERVERS_CONFIG , brokerHostAndPort );
591
587
592
588
String topic = res .getString ("topic" );
593
589
int maxMessages = res .getInt ("maxMessages" );
@@ -596,14 +592,26 @@ public static VerifiableShareConsumer createFromArgs(ArgumentParser parser, Stri
596
592
StringDeserializer deserializer = new StringDeserializer ();
597
593
KafkaShareConsumer <String , String > consumer = new KafkaShareConsumer <>(consumerProps , deserializer , deserializer );
598
594
595
+ Properties adminClientProps = new Properties ();
596
+ if (configFile != null ) {
597
+ try {
598
+ adminClientProps .putAll (Utils .loadProps (configFile ));
599
+ } catch (IOException e ) {
600
+ throw new ArgumentParserException (e .getMessage (), parser );
601
+ }
602
+ }
603
+
604
+ adminClientProps .put (CommonClientConfigs .BOOTSTRAP_SERVERS_CONFIG , brokerHostAndPort );
605
+ Admin adminClient = Admin .create (adminClientProps );
606
+
599
607
return new VerifiableShareConsumer (
600
608
consumer ,
609
+ adminClient ,
601
610
System .out ,
602
611
maxMessages ,
603
612
topic ,
604
613
acknowledgementMode ,
605
614
offsetResetStrategy ,
606
- brokerHostandPort ,
607
615
groupId ,
608
616
verbose );
609
617
}
0 commit comments