github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/topic/topicoptions/topicoptions_writer.go (about)

     1  package topicoptions
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon"
     7  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/topic/topicwriterinternal"
     8  	"github.com/ydb-platform/ydb-go-sdk/v3/topic/topictypes"
     9  	"github.com/ydb-platform/ydb-go-sdk/v3/trace"
    10  )
    11  
    12  // WriterOption options for a topic writer
    13  type WriterOption = topicwriterinternal.PublicWriterOption
    14  
    15  // WriteSessionMetadata set key-value metadata for write session.
    16  // The metadata will allow for messages of the session in topic reader.
    17  type WriteSessionMetadata map[string]string
    18  
    19  // CreateEncoderFunc for create message decoders
    20  type CreateEncoderFunc = topicwriterinternal.PublicCreateEncoderFunc
    21  
    22  // WithWriterAddEncoder add custom codec implementation to writer.
    23  // It allows to set custom codecs implementations for custom and internal codecs.
    24  func WithWriterAddEncoder(codec topictypes.Codec, f CreateEncoderFunc) WriterOption {
    25  	return topicwriterinternal.WithAddEncoder(rawtopiccommon.Codec(codec), f)
    26  }
    27  
    28  // WithWriterCheckRetryErrorFunction can override default error retry policy
    29  // use CheckErrorRetryDecisionDefault for use default behavior for the error
    30  // callback func must be fast and deterministic: always result same result for same error - it can be called
    31  // few times for every error
    32  func WithWriterCheckRetryErrorFunction(callback CheckErrorRetryFunction) WriterOption {
    33  	return func(cfg *topicwriterinternal.WriterReconnectorConfig) {
    34  		cfg.RetrySettings.CheckError = callback
    35  	}
    36  }
    37  
    38  // WithWriterCompressorCount set max count of goroutine for compress messages
    39  // must be more zero
    40  //
    41  // panic if num <= 0
    42  func WithWriterCompressorCount(num int) WriterOption {
    43  	return topicwriterinternal.WithCompressorCount(num)
    44  }
    45  
    46  // WithWriterMaxQueueLen set max len of queue for wait ack
    47  //
    48  // # Experimental
    49  //
    50  // Notice: This API is EXPERIMENTAL and may be changed or removed in a later release.
    51  func WithWriterMaxQueueLen(num int) WriterOption {
    52  	return topicwriterinternal.WithMaxQueueLen(num)
    53  }
    54  
    55  // WithWriterMessageMaxBytesSize set max body size of one message in bytes.
    56  // Writer will return error in message will be more than the size.
    57  func WithWriterMessageMaxBytesSize(size int) WriterOption {
    58  	return func(cfg *topicwriterinternal.WriterReconnectorConfig) {
    59  		cfg.MaxMessageSize = size
    60  	}
    61  }
    62  
    63  // WithWriteSessionMeta
    64  // Deprecated: (was experimental) will be removed soon.
    65  // Use WithWriterSessionMeta instead
    66  func WithWriteSessionMeta(meta map[string]string) WriterOption {
    67  	return WithWriterSessionMeta(meta)
    68  }
    69  
    70  // WithWriterSessionMeta set writer's session metadata
    71  func WithWriterSessionMeta(meta map[string]string) WriterOption {
    72  	return topicwriterinternal.WithSessionMeta(meta)
    73  }
    74  
    75  // WithProducerID
    76  // Deprecated: (was experimental) will be removed soon.
    77  // Use WithWriterProducerID instead
    78  func WithProducerID(producerID string) WriterOption {
    79  	return WithWriterProducerID(producerID)
    80  }
    81  
    82  // WithWriterProducerID set producer for write session
    83  func WithWriterProducerID(producerID string) WriterOption {
    84  	return topicwriterinternal.WithProducerID(producerID)
    85  }
    86  
    87  // WithPartitionID
    88  // Deprecated: (was experimental) will be removed soon
    89  // Use WithWriterPartitionID instead
    90  func WithPartitionID(partitionID int64) WriterOption {
    91  	return WithWriterPartitionID(partitionID)
    92  }
    93  
    94  // WithWriterPartitionID set direct partition id on write session level
    95  func WithWriterPartitionID(partitionID int64) WriterOption {
    96  	return topicwriterinternal.WithPartitioning(topicwriterinternal.NewPartitioningWithPartitionID(partitionID))
    97  }
    98  
    99  // WithSyncWrite
   100  // Deprecated: (was experimental) use WithWriterWaitServerAck instead
   101  func WithSyncWrite(sync bool) WriterOption {
   102  	return WithWriterWaitServerAck(sync)
   103  }
   104  
   105  // WithWriterWaitServerAck - when enabled every Write call wait ack from server for all messages from the call
   106  // disabled by default. Make writer much slower, use only if you really need it.
   107  func WithWriterWaitServerAck(wait bool) WriterOption {
   108  	return topicwriterinternal.WithWaitAckOnWrite(wait)
   109  }
   110  
   111  type (
   112  	// WithOnWriterConnectedInfo present information, received from server
   113  	// Deprecated: (was experimental) will be removed soon
   114  	WithOnWriterConnectedInfo = topicwriterinternal.PublicWithOnWriterConnectedInfo
   115  
   116  	// OnWriterInitResponseCallback
   117  	// Deprecated: (was experimental) will be removed soon.
   118  	OnWriterInitResponseCallback = topicwriterinternal.PublicOnWriterInitResponseCallback
   119  )
   120  
   121  // WithOnWriterFirstConnected set callback f, which will called once - after first successfully init topic writer stream
   122  // Deprecated: (was experimental) will be removed soon.
   123  // Use Writer.WaitInit function instead
   124  func WithOnWriterFirstConnected(f OnWriterInitResponseCallback) WriterOption {
   125  	return func(cfg *topicwriterinternal.WriterReconnectorConfig) {
   126  		cfg.OnWriterInitResponseCallback = f
   127  	}
   128  }
   129  
   130  // WithCodec
   131  // Deprecated: (was experimental) will be removed soon.
   132  // Use WithWriterCodec instead
   133  func WithCodec(codec topictypes.Codec) WriterOption {
   134  	return WithWriterCodec(codec)
   135  }
   136  
   137  // WithWriterCodec disable codec auto select and force set codec for the write session
   138  func WithWriterCodec(codec topictypes.Codec) WriterOption {
   139  	return topicwriterinternal.WithCodec(rawtopiccommon.Codec(codec))
   140  }
   141  
   142  // WithCodecAutoSelect
   143  // Deprecated: (was experimental) will be removed soon.
   144  // Use WithWriterCodecAutoSelect instead.
   145  func WithCodecAutoSelect() WriterOption {
   146  	return topicwriterinternal.WithAutoCodec()
   147  }
   148  
   149  // WithWriterCodecAutoSelect - auto select best codec for messages stream
   150  // enabled by default
   151  // if option enabled - send a batch of messages for every allowed codec (for prevent delayed bad codec accident)
   152  // then from time to time measure all codecs and select codec with the smallest result messages size
   153  func WithWriterCodecAutoSelect() WriterOption {
   154  	return topicwriterinternal.WithAutoCodec()
   155  }
   156  
   157  // WithWriterSetAutoSeqNo set messages SeqNo by SDK
   158  // enabled by default
   159  // if enabled - Message.SeqNo field must be zero
   160  func WithWriterSetAutoSeqNo(val bool) WriterOption {
   161  	return topicwriterinternal.WithAutoSetSeqNo(val)
   162  }
   163  
   164  // WithWriterSetAutoCreatedAt set messages CreatedAt by SDK
   165  // enabled by default
   166  // if enabled - Message.CreatedAt field must be zero
   167  func WithWriterSetAutoCreatedAt(val bool) WriterOption {
   168  	return topicwriterinternal.WithAutosetCreatedTime(val)
   169  }
   170  
   171  // WithWriterStartTimeout mean timeout for connect to writer stream and work some time without errors
   172  func WithWriterStartTimeout(timeout time.Duration) WriterOption {
   173  	return topicwriterinternal.WithStartTimeout(timeout)
   174  }
   175  
   176  // WithWriterTrace set tracer for the writer
   177  func WithWriterTrace(t trace.Topic) WriterOption { //nolint:gocritic
   178  	return topicwriterinternal.WithTrace(&t)
   179  }
   180  
   181  // WithWriterUpdateTokenInterval set time interval between send auth token to the server
   182  func WithWriterUpdateTokenInterval(interval time.Duration) WriterOption {
   183  	return topicwriterinternal.WithTokenUpdateInterval(interval)
   184  }