github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/topic/topicwriterinternal/writer_options.go (about) 1 package topicwriterinternal 2 3 import ( 4 "time" 5 6 "github.com/ydb-platform/ydb-go-sdk/v3/credentials" 7 "github.com/ydb-platform/ydb-go-sdk/v3/internal/config" 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon" 9 "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopicwriter" 10 "github.com/ydb-platform/ydb-go-sdk/v3/trace" 11 ) 12 13 type PublicWriterOption func(cfg *WriterReconnectorConfig) 14 15 func WithAddEncoder(codec rawtopiccommon.Codec, encoderFunc PublicCreateEncoderFunc) PublicWriterOption { 16 return func(cfg *WriterReconnectorConfig) { 17 if cfg.AdditionalEncoders == nil { 18 cfg.AdditionalEncoders = map[rawtopiccommon.Codec]PublicCreateEncoderFunc{} 19 } 20 cfg.AdditionalEncoders[codec] = encoderFunc 21 } 22 } 23 24 func WithAutoSetSeqNo(val bool) PublicWriterOption { 25 return func(cfg *WriterReconnectorConfig) { 26 cfg.AutoSetSeqNo = val 27 } 28 } 29 30 func WithAutoCodec() PublicWriterOption { 31 return func(cfg *WriterReconnectorConfig) { 32 cfg.forceCodec = rawtopiccommon.CodecUNSPECIFIED 33 } 34 } 35 36 func WithCompressorCount(num int) PublicWriterOption { 37 if num <= 0 { 38 panic("ydb: compressor count must be > 0") 39 } 40 41 return func(cfg *WriterReconnectorConfig) { 42 cfg.compressorCount = num 43 } 44 } 45 46 func WithTokenUpdateInterval(interval time.Duration) PublicWriterOption { 47 return func(cfg *WriterReconnectorConfig) { 48 cfg.credUpdateInterval = interval 49 } 50 } 51 52 // WithCommonConfig 53 // 54 // # Experimental 55 // 56 // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release. 57 func WithCommonConfig(common config.Common) PublicWriterOption { 58 return func(cfg *WriterReconnectorConfig) { 59 cfg.Common = common 60 } 61 } 62 63 // WithCredentials for internal usage only 64 // no proxy to public interface 65 func WithCredentials(cred credentials.Credentials) PublicWriterOption { 66 return func(cfg *WriterReconnectorConfig) { 67 if cred == nil { 68 cred = credentials.NewAnonymousCredentials() 69 } 70 cfg.cred = cred 71 } 72 } 73 74 func WithCodec(codec rawtopiccommon.Codec) PublicWriterOption { 75 return func(cfg *WriterReconnectorConfig) { 76 cfg.forceCodec = codec 77 } 78 } 79 80 func WithConnectFunc(connect ConnectFunc) PublicWriterOption { 81 return func(cfg *WriterReconnectorConfig) { 82 cfg.Connect = connect 83 } 84 } 85 86 func WithConnectTimeout(timeout time.Duration) PublicWriterOption { 87 return func(cfg *WriterReconnectorConfig) { 88 cfg.connectTimeout = timeout 89 } 90 } 91 92 func WithAutosetCreatedTime(enable bool) PublicWriterOption { 93 return func(cfg *WriterReconnectorConfig) { 94 cfg.AutoSetCreatedTime = enable 95 } 96 } 97 98 func WithMaxQueueLen(num int) PublicWriterOption { 99 return func(cfg *WriterReconnectorConfig) { 100 cfg.MaxQueueLen = num 101 } 102 } 103 104 func WithPartitioning(partitioning PublicFuturePartitioning) PublicWriterOption { 105 return func(cfg *WriterReconnectorConfig) { 106 cfg.defaultPartitioning = partitioning.ToRaw() 107 } 108 } 109 110 func WithProducerID(producerID string) PublicWriterOption { 111 return func(cfg *WriterReconnectorConfig) { 112 cfg.producerID = producerID 113 oldPartitioningType := cfg.defaultPartitioning.Type 114 if oldPartitioningType == rawtopicwriter.PartitioningUndefined || 115 oldPartitioningType == rawtopicwriter.PartitioningMessageGroupID { 116 WithPartitioning(NewPartitioningWithMessageGroupID(producerID))(cfg) 117 } 118 } 119 } 120 121 func WithSessionMeta(meta map[string]string) PublicWriterOption { 122 return func(cfg *WriterReconnectorConfig) { 123 if len(meta) == 0 { 124 cfg.writerMeta = nil 125 } else { 126 cfg.writerMeta = make(map[string]string, len(meta)) 127 for k, v := range meta { 128 cfg.writerMeta[k] = v 129 } 130 } 131 } 132 } 133 134 func WithStartTimeout(timeout time.Duration) PublicWriterOption { 135 return func(cfg *WriterReconnectorConfig) { 136 cfg.RetrySettings.StartTimeout = timeout 137 } 138 } 139 140 func WithWaitAckOnWrite(val bool) PublicWriterOption { 141 return func(cfg *WriterReconnectorConfig) { 142 cfg.WaitServerAck = val 143 } 144 } 145 146 func WithTrace(tracer *trace.Topic) PublicWriterOption { 147 return func(cfg *WriterReconnectorConfig) { 148 cfg.tracer = cfg.tracer.Compose(tracer) 149 } 150 } 151 152 func WithTopic(topic string) PublicWriterOption { 153 return func(cfg *WriterReconnectorConfig) { 154 cfg.topic = topic 155 } 156 }