18
18
19
19
import java .time .Duration ;
20
20
import java .util .HashMap ;
21
+ import java .util .HashSet ;
21
22
import java .util .Map ;
22
23
import java .util .Set ;
23
24
import java .util .SortedMap ;
37
38
38
39
import org .springframework .boot .context .properties .ConfigurationProperties ;
39
40
import org .springframework .boot .context .properties .PropertyMapper ;
41
+ import org .springframework .lang .Nullable ;
40
42
import org .springframework .pulsar .listener .AckMode ;
41
43
import org .springframework .util .CollectionUtils ;
42
44
import org .springframework .util .StringUtils ;
@@ -507,11 +509,22 @@ public static class Producer {
507
509
*/
508
510
private Duration batchingMaxPublishDelay = Duration .ofMillis (1 );
509
511
512
+ /**
513
+ * Partition switch frequency while batching of messages is enabled and using
514
+ * round-robin routing mode for non-keyed message.
515
+ */
516
+ private Integer batchingPartitionSwitchFrequencyByPublishDelay = 10 ;
517
+
510
518
/**
511
519
* Maximum number of messages to be batched.
512
520
*/
513
521
private Integer batchingMaxMessages = 1000 ;
514
522
523
+ /**
524
+ * Maximum number of bytes permitted in a batch.
525
+ */
526
+ private DataSize batchingMaxBytes = DataSize .ofKilobytes (128 );
527
+
515
528
/**
516
529
* Whether to automatically batch messages.
517
530
*/
@@ -522,16 +535,53 @@ public static class Producer {
522
535
*/
523
536
private Boolean chunkingEnabled = false ;
524
537
538
+ /**
539
+ * Names of the public encryption keys to use when encrypting data.
540
+ */
541
+ private Set <String > encryptionKeys = new HashSet <>();
542
+
525
543
/**
526
544
* Message compression type.
527
545
*/
528
546
private CompressionType compressionType ;
529
547
548
+ /**
549
+ * Baseline for the sequence ids for messages published by the producer.
550
+ */
551
+ @ Nullable
552
+ private Long initialSequenceId ;
553
+
554
+ /**
555
+ * Whether partitioned producer automatically discover new partitions at runtime.
556
+ */
557
+ private Boolean autoUpdatePartitions = true ;
558
+
559
+ /**
560
+ * Interval of partitions discovery updates.
561
+ */
562
+ private Duration autoUpdatePartitionsInterval = Duration .ofMinutes (1 );
563
+
564
+ /**
565
+ * Whether the multiple schema mode is enabled.
566
+ */
567
+ private Boolean multiSchema = true ;
568
+
530
569
/**
531
570
* Type of access to the topic the producer requires.
532
571
*/
533
572
private ProducerAccessMode producerAccessMode = ProducerAccessMode .Shared ;
534
573
574
+ /**
575
+ * Whether producers in Shared mode register and connect immediately to the owner
576
+ * broker of each partition or start lazily on demand.
577
+ */
578
+ private Boolean lazyStartPartitionedProducers = false ;
579
+
580
+ /**
581
+ * Map of properties to add to the producer.
582
+ */
583
+ private Map <String , String > properties = new HashMap <>();
584
+
535
585
private Cache cache = new Cache ();
536
586
537
587
public String getTopicName () {
@@ -558,7 +608,7 @@ public void setSendTimeout(Duration sendTimeout) {
558
608
this .sendTimeout = sendTimeout ;
559
609
}
560
610
561
- public Boolean isBlockIfQueueFull () {
611
+ public Boolean getBlockIfQueueFull () {
562
612
return this .blockIfQueueFull ;
563
613
}
564
614
@@ -614,6 +664,15 @@ public void setBatchingMaxPublishDelay(Duration batchingMaxPublishDelay) {
614
664
this .batchingMaxPublishDelay = batchingMaxPublishDelay ;
615
665
}
616
666
667
+ public Integer getBatchingPartitionSwitchFrequencyByPublishDelay () {
668
+ return this .batchingPartitionSwitchFrequencyByPublishDelay ;
669
+ }
670
+
671
+ public void setBatchingPartitionSwitchFrequencyByPublishDelay (
672
+ Integer batchingPartitionSwitchFrequencyByPublishDelay ) {
673
+ this .batchingPartitionSwitchFrequencyByPublishDelay = batchingPartitionSwitchFrequencyByPublishDelay ;
674
+ }
675
+
617
676
public Integer getBatchingMaxMessages () {
618
677
return this .batchingMaxMessages ;
619
678
}
@@ -622,22 +681,38 @@ public void setBatchingMaxMessages(Integer batchingMaxMessages) {
622
681
this .batchingMaxMessages = batchingMaxMessages ;
623
682
}
624
683
625
- public Boolean isBatchingEnabled () {
684
+ public DataSize getBatchingMaxBytes () {
685
+ return this .batchingMaxBytes ;
686
+ }
687
+
688
+ public void setBatchingMaxBytes (DataSize batchingMaxBytes ) {
689
+ this .batchingMaxBytes = batchingMaxBytes ;
690
+ }
691
+
692
+ public Boolean getBatchingEnabled () {
626
693
return this .batchingEnabled ;
627
694
}
628
695
629
696
public void setBatchingEnabled (Boolean batchingEnabled ) {
630
697
this .batchingEnabled = batchingEnabled ;
631
698
}
632
699
633
- public Boolean isChunkingEnabled () {
700
+ public Boolean getChunkingEnabled () {
634
701
return this .chunkingEnabled ;
635
702
}
636
703
637
704
public void setChunkingEnabled (Boolean chunkingEnabled ) {
638
705
this .chunkingEnabled = chunkingEnabled ;
639
706
}
640
707
708
+ public Set <String > getEncryptionKeys () {
709
+ return this .encryptionKeys ;
710
+ }
711
+
712
+ public void setEncryptionKeys (Set <String > encryptionKeys ) {
713
+ this .encryptionKeys = encryptionKeys ;
714
+ }
715
+
641
716
public CompressionType getCompressionType () {
642
717
return this .compressionType ;
643
718
}
@@ -646,6 +721,39 @@ public void setCompressionType(CompressionType compressionType) {
646
721
this .compressionType = compressionType ;
647
722
}
648
723
724
+ @ Nullable
725
+ public Long getInitialSequenceId () {
726
+ return this .initialSequenceId ;
727
+ }
728
+
729
+ public void setInitialSequenceId (@ Nullable Long initialSequenceId ) {
730
+ this .initialSequenceId = initialSequenceId ;
731
+ }
732
+
733
+ public Boolean getAutoUpdatePartitions () {
734
+ return this .autoUpdatePartitions ;
735
+ }
736
+
737
+ public void setAutoUpdatePartitions (Boolean autoUpdatePartitions ) {
738
+ this .autoUpdatePartitions = autoUpdatePartitions ;
739
+ }
740
+
741
+ public Duration getAutoUpdatePartitionsInterval () {
742
+ return this .autoUpdatePartitionsInterval ;
743
+ }
744
+
745
+ public void setAutoUpdatePartitionsInterval (Duration autoUpdatePartitionsInterval ) {
746
+ this .autoUpdatePartitionsInterval = autoUpdatePartitionsInterval ;
747
+ }
748
+
749
+ public Boolean getMultiSchema () {
750
+ return this .multiSchema ;
751
+ }
752
+
753
+ public void setMultiSchema (Boolean multiSchema ) {
754
+ this .multiSchema = multiSchema ;
755
+ }
756
+
649
757
public ProducerAccessMode getProducerAccessMode () {
650
758
return this .producerAccessMode ;
651
759
}
@@ -654,6 +762,22 @@ public void setProducerAccessMode(ProducerAccessMode producerAccessMode) {
654
762
this .producerAccessMode = producerAccessMode ;
655
763
}
656
764
765
+ public Boolean getLazyStartPartitionedProducers () {
766
+ return this .lazyStartPartitionedProducers ;
767
+ }
768
+
769
+ public void setLazyStartPartitionedProducers (Boolean lazyStartPartitionedProducers ) {
770
+ this .lazyStartPartitionedProducers = lazyStartPartitionedProducers ;
771
+ }
772
+
773
+ public Map <String , String > getProperties () {
774
+ return this .properties ;
775
+ }
776
+
777
+ public void setProperties (Map <String , String > properties ) {
778
+ this .properties = properties ;
779
+ }
780
+
657
781
public Cache getCache () {
658
782
return this .cache ;
659
783
}
@@ -665,8 +789,8 @@ public Map<String, Object> buildProperties() {
665
789
666
790
map .from (this ::getTopicName ).to (properties .in ("topicName" ));
667
791
map .from (this ::getProducerName ).to (properties .in ("producerName" ));
668
- map .from (this ::getSendTimeout ).as (Duration ::toMillis ).to (properties .in ("sendTimeoutMs" ));
669
- map .from (this ::isBlockIfQueueFull ).to (properties .in ("blockIfQueueFull" ));
792
+ map .from (this ::getSendTimeout ).asInt (Duration ::toMillis ).to (properties .in ("sendTimeoutMs" ));
793
+ map .from (this ::getBlockIfQueueFull ).to (properties .in ("blockIfQueueFull" ));
670
794
map .from (this ::getMaxPendingMessages ).to (properties .in ("maxPendingMessages" ));
671
795
map .from (this ::getMaxPendingMessagesAcrossPartitions )
672
796
.to (properties .in ("maxPendingMessagesAcrossPartitions" ));
@@ -675,11 +799,22 @@ public Map<String, Object> buildProperties() {
675
799
map .from (this ::getCryptoFailureAction ).to (properties .in ("cryptoFailureAction" ));
676
800
map .from (this ::getBatchingMaxPublishDelay ).as (it -> it .toNanos () / 1000 )
677
801
.to (properties .in ("batchingMaxPublishDelayMicros" ));
802
+ map .from (this ::getBatchingPartitionSwitchFrequencyByPublishDelay )
803
+ .to (properties .in ("batchingPartitionSwitchFrequencyByPublishDelay" ));
678
804
map .from (this ::getBatchingMaxMessages ).to (properties .in ("batchingMaxMessages" ));
679
- map .from (this ::isBatchingEnabled ).to (properties .in ("batchingEnabled" ));
680
- map .from (this ::isChunkingEnabled ).to (properties .in ("chunkingEnabled" ));
805
+ map .from (this ::getBatchingMaxBytes ).asInt (DataSize ::toBytes ).to (properties .in ("batchingMaxBytes" ));
806
+ map .from (this ::getBatchingEnabled ).to (properties .in ("batchingEnabled" ));
807
+ map .from (this ::getChunkingEnabled ).to (properties .in ("chunkingEnabled" ));
808
+ map .from (this ::getEncryptionKeys ).to (properties .in ("encryptionKeys" ));
681
809
map .from (this ::getCompressionType ).to (properties .in ("compressionType" ));
810
+ map .from (this ::getInitialSequenceId ).to (properties .in ("initialSequenceId" ));
811
+ map .from (this ::getAutoUpdatePartitions ).to (properties .in ("autoUpdatePartitions" ));
812
+ map .from (this ::getAutoUpdatePartitionsInterval ).as (Duration ::toMillis )
813
+ .to (properties .in ("autoUpdatePartitionsInterval" ));
814
+ map .from (this ::getMultiSchema ).to (properties .in ("multiSchema" ));
682
815
map .from (this ::getProducerAccessMode ).to (properties .in ("accessMode" ));
816
+ map .from (this ::getLazyStartPartitionedProducers ).to (properties .in ("lazyStartPartitionedProducers" ));
817
+ map .from (this ::getProperties ).to (properties .in ("properties" ));
683
818
684
819
return properties ;
685
820
}
0 commit comments