github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/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: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
    49  func WithWriterMaxQueueLen(num int) WriterOption {
    50  	return topicwriterinternal.WithMaxQueueLen(num)
    51  }
    52  
    53  // WithWriterMessageMaxBytesSize set max body size of one message in bytes.
    54  // Writer will return error in message will be more than the size.
    55  func WithWriterMessageMaxBytesSize(size int) WriterOption {
    56  	return func(cfg *topicwriterinternal.WriterReconnectorConfig) {
    57  		cfg.MaxMessageSize = size
    58  	}
    59  }
    60  
    61  // WithWriteSessionMeta
    62  //
    63  // Deprecated: was experimental and not actual now.
    64  // Use WithWriterSessionMeta instead.
    65  // Will be removed after Oct 2024.
    66  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
    67  func WithWriteSessionMeta(meta map[string]string) WriterOption {
    68  	return WithWriterSessionMeta(meta)
    69  }
    70  
    71  // WithWriterSessionMeta set writer's session metadata
    72  func WithWriterSessionMeta(meta map[string]string) WriterOption {
    73  	return topicwriterinternal.WithSessionMeta(meta)
    74  }
    75  
    76  // WithProducerID
    77  //
    78  // Deprecated: was experimental and not actual now.
    79  // Use WithWriterProducerID instead.
    80  // Will be removed after Oct 2024.
    81  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
    82  func WithProducerID(producerID string) WriterOption {
    83  	return WithWriterProducerID(producerID)
    84  }
    85  
    86  // WithWriterProducerID set producer for write session
    87  func WithWriterProducerID(producerID string) WriterOption {
    88  	return topicwriterinternal.WithProducerID(producerID)
    89  }
    90  
    91  // WithPartitionID
    92  //
    93  // Deprecated: was experimental and not actual now.
    94  // Use WithWriterPartitionID instead.
    95  // Will be removed after Oct 2024.
    96  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
    97  func WithPartitionID(partitionID int64) WriterOption {
    98  	return WithWriterPartitionID(partitionID)
    99  }
   100  
   101  // WithWriterPartitionID set direct partition id on write session level
   102  func WithWriterPartitionID(partitionID int64) WriterOption {
   103  	return topicwriterinternal.WithPartitioning(topicwriterinternal.NewPartitioningWithPartitionID(partitionID))
   104  }
   105  
   106  // WithSyncWrite
   107  //
   108  // Deprecated: was experimental and not actual now.
   109  // Use WithWriterWaitServerAck instead.
   110  // Will be removed after Oct 2024.
   111  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
   112  func WithSyncWrite(sync bool) WriterOption {
   113  	return WithWriterWaitServerAck(sync)
   114  }
   115  
   116  // WithWriterWaitServerAck - when enabled every Write call wait ack from server for all messages from the call
   117  // disabled by default. Make writer much slower, use only if you really need it.
   118  func WithWriterWaitServerAck(wait bool) WriterOption {
   119  	return topicwriterinternal.WithWaitAckOnWrite(wait)
   120  }
   121  
   122  type (
   123  	// WithOnWriterConnectedInfo present information, received from server
   124  	//
   125  	// Deprecated: was experimental and not actual now.
   126  	// Will be removed after Oct 2024.
   127  	// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
   128  	WithOnWriterConnectedInfo = topicwriterinternal.PublicWithOnWriterConnectedInfo
   129  
   130  	// OnWriterInitResponseCallback
   131  	//
   132  	// Deprecated: was experimental and not actual now.
   133  	// Will be removed after Oct 2024.
   134  	// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
   135  	OnWriterInitResponseCallback = topicwriterinternal.PublicOnWriterInitResponseCallback
   136  )
   137  
   138  // WithOnWriterFirstConnected set callback f, which will called once - after first successfully init topic writer stream
   139  //
   140  // Deprecated: was experimental and not actual now.
   141  // Use Writer.WaitInit function instead.
   142  // Will be removed after Oct 2024.
   143  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
   144  func WithOnWriterFirstConnected(f OnWriterInitResponseCallback) WriterOption {
   145  	return func(cfg *topicwriterinternal.WriterReconnectorConfig) {
   146  		cfg.OnWriterInitResponseCallback = f
   147  	}
   148  }
   149  
   150  // WithCodec
   151  //
   152  // Deprecated: was experimental and not actual now.
   153  // Use WithWriterCodec instead.
   154  // Will be removed after Oct 2024.
   155  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
   156  func WithCodec(codec topictypes.Codec) WriterOption {
   157  	return WithWriterCodec(codec)
   158  }
   159  
   160  // WithWriterCodec disable codec auto select and force set codec for the write session
   161  func WithWriterCodec(codec topictypes.Codec) WriterOption {
   162  	return topicwriterinternal.WithCodec(rawtopiccommon.Codec(codec))
   163  }
   164  
   165  // WithCodecAutoSelect
   166  //
   167  // Deprecated: was experimental and not actual now.
   168  // Use WithWriterCodecAutoSelect instead.
   169  // Will be removed after Oct 2024.
   170  // Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
   171  func WithCodecAutoSelect() WriterOption {
   172  	return topicwriterinternal.WithAutoCodec()
   173  }
   174  
   175  // WithWriterCodecAutoSelect - auto select best codec for messages stream
   176  // enabled by default
   177  // if option enabled - send a batch of messages for every allowed codec (for prevent delayed bad codec accident)
   178  // then from time to time measure all codecs and select codec with the smallest result messages size
   179  func WithWriterCodecAutoSelect() WriterOption {
   180  	return topicwriterinternal.WithAutoCodec()
   181  }
   182  
   183  // WithWriterSetAutoSeqNo set messages SeqNo by SDK
   184  // enabled by default
   185  // if enabled - Message.SeqNo field must be zero
   186  func WithWriterSetAutoSeqNo(val bool) WriterOption {
   187  	return topicwriterinternal.WithAutoSetSeqNo(val)
   188  }
   189  
   190  // WithWriterSetAutoCreatedAt set messages CreatedAt by SDK
   191  // enabled by default
   192  // if enabled - Message.CreatedAt field must be zero
   193  func WithWriterSetAutoCreatedAt(val bool) WriterOption {
   194  	return topicwriterinternal.WithAutosetCreatedTime(val)
   195  }
   196  
   197  // WithWriterStartTimeout mean timeout for connect to writer stream and work some time without errors
   198  func WithWriterStartTimeout(timeout time.Duration) WriterOption {
   199  	return topicwriterinternal.WithStartTimeout(timeout)
   200  }
   201  
   202  // WithWriterTrace set tracer for the writer
   203  func WithWriterTrace(t trace.Topic) WriterOption { //nolint:gocritic
   204  	return topicwriterinternal.WithTrace(&t)
   205  }
   206  
   207  // WithWriterUpdateTokenInterval set time interval between send auth token to the server
   208  func WithWriterUpdateTokenInterval(interval time.Duration) WriterOption {
   209  	return topicwriterinternal.WithTokenUpdateInterval(interval)
   210  }