@@ -691,17 +691,7 @@ private Producer<K, V> getOrCreateThreadBoundProducer() {
691
691
* @return the producer.
692
692
*/
693
693
protected Producer <K , V > createKafkaProducer () {
694
- Map <String , Object > newConfigs ;
695
- if (this .clientIdPrefix == null ) {
696
- newConfigs = new HashMap <>(this .configs );
697
- }
698
- else {
699
- newConfigs = new HashMap <>(this .configs );
700
- newConfigs .put (ProducerConfig .CLIENT_ID_CONFIG ,
701
- this .clientIdPrefix + "-" + this .clientIdCounter .incrementAndGet ());
702
- }
703
- checkBootstrap (newConfigs );
704
- return createRawProducer (newConfigs );
694
+ return createRawProducer (getProducerConfigs ());
705
695
}
706
696
707
697
protected Producer <K , V > createTransactionalProducerForPartition () {
@@ -826,17 +816,7 @@ boolean cacheReturner(CloseSafeProducer<K, V> producerToRemove, Duration timeout
826
816
827
817
private CloseSafeProducer <K , V > doCreateTxProducer (String prefix , String suffix ,
828
818
BiPredicate <CloseSafeProducer <K , V >, Duration > remover ) {
829
-
830
- Producer <K , V > newProducer ;
831
- Map <String , Object > newProducerConfigs = new HashMap <>(this .configs );
832
- String txId = prefix + suffix ;
833
- newProducerConfigs .put (ProducerConfig .TRANSACTIONAL_ID_CONFIG , txId );
834
- if (this .clientIdPrefix != null ) {
835
- newProducerConfigs .put (ProducerConfig .CLIENT_ID_CONFIG ,
836
- this .clientIdPrefix + "-" + this .clientIdCounter .incrementAndGet ());
837
- }
838
- checkBootstrap (newProducerConfigs );
839
- newProducer = createRawProducer (newProducerConfigs );
819
+ Producer <K , V > newProducer = createRawProducer (getTxProducerConfigs (prefix + suffix ));
840
820
try {
841
821
newProducer .initTransactions ();
842
822
}
@@ -908,6 +888,35 @@ public void closeThreadBoundProducer() {
908
888
}
909
889
}
910
890
891
+ /**
892
+ * Return the configuration of a producer.
893
+ * @return the configuration of a producer.
894
+ * @since 2.8.3
895
+ * @see #createKafkaProducer()
896
+ */
897
+ protected Map <String , Object > getProducerConfigs () {
898
+ final Map <String , Object > newProducerConfigs = new HashMap <>(this .configs );
899
+ checkBootstrap (newProducerConfigs );
900
+ if (this .clientIdPrefix != null ) {
901
+ newProducerConfigs .put (ProducerConfig .CLIENT_ID_CONFIG ,
902
+ this .clientIdPrefix + "-" + this .clientIdCounter .incrementAndGet ());
903
+ }
904
+ return newProducerConfigs ;
905
+ }
906
+
907
+ /**
908
+ * Return the configuration of a transactional producer.
909
+ * @param transactionId the transactionId.
910
+ * @return the configuration of a transactional producer.
911
+ * @since 2.8.3
912
+ * @see #doCreateTxProducer(String, String, BiPredicate)
913
+ */
914
+ protected Map <String , Object > getTxProducerConfigs (String transactionId ) {
915
+ final Map <String , Object > newProducerConfigs = getProducerConfigs ();
916
+ newProducerConfigs .put (ProducerConfig .TRANSACTIONAL_ID_CONFIG , transactionId );
917
+ return newProducerConfigs ;
918
+ }
919
+
911
920
/**
912
921
* A wrapper class for the delegate.
913
922
*
0 commit comments