コード例 #1
0
ファイル: RequestContext.cs プロジェクト: ligu/KafkaClient
 public RequestContext(int?correlationId = null, short?version = null, string clientId = null, IImmutableDictionary <string, IProtocolTypeEncoder> encoders = null, string protocolType = null, ProduceRequestMessages onProduceRequestMessages = null)
 {
     CorrelationId            = correlationId.GetValueOrDefault(1);
     ApiVersion               = version;
     ClientId                 = clientId ?? DefaultClientId;
     Encoders                 = encoders ?? ImmutableDictionary <string, IProtocolTypeEncoder> .Empty;
     ProtocolType             = protocolType;
     OnProduceRequestMessages = onProduceRequestMessages;
 }
コード例 #2
0
 public static IConnectionConfiguration CopyWith(
     this IConnectionConfiguration configuration,
     IRetry connectionRetry                    = null,
     IVersionSupport versionSupport            = null,
     TimeSpan?requestTimeout                   = null,
     int?readBufferSize                        = null,
     int?writeBufferSize                       = null,
     bool?isTcpKeepalive                       = null,
     IEnumerable <IMembershipEncoder> encoders = null,
     ISslConfiguration sslConfiguration        = null,
     ConnectError onDisconnected               = null,
     Connecting onConnecting                   = null,
     Connecting onConnected                    = null,
     Writing onWriting            = null,
     StartingBytes onWritingBytes = null,
     FinishedBytes onWroteBytes   = null,
     WriteSuccess onWritten       = null,
     WriteError onWriteFailed     = null,
     Reading onReading            = null,
     StartingBytes onReadingBytes = null,
     FinishedBytes onReadBytes    = null,
     ReadSuccess onRead           = null,
     ReadError onReadFailed       = null,
     ProduceRequestMessages onProduceRequestMessages = null)
 {
     return(new ConnectionConfiguration(
                connectionRetry ?? configuration.ConnectionRetry,
                versionSupport ?? configuration.VersionSupport,
                requestTimeout ?? configuration.RequestTimeout,
                readBufferSize ?? configuration.ReadBufferSize,
                writeBufferSize ?? configuration.WriteBufferSize,
                isTcpKeepalive ?? configuration.IsTcpKeepalive,
                encoders ?? configuration.Encoders.Values,
                sslConfiguration ?? configuration.SslConfiguration,
                onDisconnected ?? configuration.OnDisconnected,
                onConnecting ?? configuration.OnConnecting,
                onConnected ?? configuration.OnConnected,
                onWriting ?? configuration.OnWriting,
                onWritingBytes ?? configuration.OnWritingBytes,
                onWroteBytes ?? configuration.OnWroteBytes,
                onWritten ?? configuration.OnWritten,
                onWriteFailed ?? configuration.OnWriteFailed,
                onReading ?? configuration.OnReading,
                onReadingBytes ?? configuration.OnReadingBytes,
                onReadBytes ?? configuration.OnReadBytes,
                onRead ?? configuration.OnRead,
                onReadFailed ?? configuration.OnReadFailed,
                onProduceRequestMessages ?? configuration.OnProduceRequestMessages));
 }
コード例 #3
0
 /// <summary>
 /// Configuration for the tcp connection.
 /// </summary>
 /// <param name="connectionRetry">Retry details for (re)establishing the connection.</param>
 /// <param name="versionSupport">Support for different protocol versions for Kakfa requests and responses.</param>
 /// <param name="requestTimeout">The maximum time to wait for requests.</param>
 /// <param name="readBufferSize">The buffer size to use for the socket, when receiving bytes.</param>
 /// <param name="writeBufferSize">The buffer size to use for the socket, when sending bytes.</param>
 /// <param name="isTcpKeepalive">TCP keepalive option.</param>
 /// <param name="encoders">Custom Encoding support for different protocol types</param>
 /// <param name="sslConfiguration">Configuration for SSL encrypted communication</param>
 /// <param name="onDisconnected">Triggered when the tcp socket is disconnected.</param>
 /// <param name="onConnecting">Triggered when the tcp socket is connecting.</param>
 /// <param name="onConnected">Triggered after the tcp socket is successfully connected.</param>
 /// <param name="onWriting">Triggered when writing to the tcp stream.</param>
 /// <param name="onWritingBytes">Triggered when writing a chunk of bytes to the tcp stream.</param>
 /// <param name="onWroteBytes">Triggered after successfully writing a chunk of bytes to the tcp stream.</param>
 /// <param name="onWritten">Triggered after having successfully written to the tcp stream.</param>
 /// <param name="onWriteFailed">Triggered after failing to write to the tcp stream.</param>
 /// <param name="onReading">Triggered when starting to read a message's bytes from the tcp stream.</param>
 /// <param name="onReadingBytes">Triggered when reading a chunk of bytes from the tcp stream.</param>
 /// <param name="onReadBytes">Triggered after successfully reading a chunk of bytes from the tcp stream.</param>
 /// <param name="onRead">Triggered after having successfully read a message's bytes from the tcp stream.</param>
 /// <param name="onReadFailed">Triggered after failing to read from the tcp stream.</param>
 /// <param name="onProduceRequestMessages">Triggered when encoding ProduceRequest messages.</param>
 public ConnectionConfiguration(
     IRetry connectionRetry                    = null,
     IVersionSupport versionSupport            = null,
     TimeSpan?requestTimeout                   = null,
     int?readBufferSize                        = null,
     int?writeBufferSize                       = null,
     bool?isTcpKeepalive                       = null,
     IEnumerable <IMembershipEncoder> encoders = null,
     ISslConfiguration sslConfiguration        = null,
     ConnectError onDisconnected               = null,
     Connecting onConnecting                   = null,
     Connecting onConnected                    = null,
     Writing onWriting            = null,
     StartingBytes onWritingBytes = null,
     FinishedBytes onWroteBytes   = null,
     WriteSuccess onWritten       = null,
     WriteError onWriteFailed     = null,
     Reading onReading            = null,
     StartingBytes onReadingBytes = null,
     FinishedBytes onReadBytes    = null,
     ReadSuccess onRead           = null,
     ReadError onReadFailed       = null,
     ProduceRequestMessages onProduceRequestMessages = null
     )
 {
     ConnectionRetry          = connectionRetry ?? Defaults.ConnectionRetry();
     VersionSupport           = versionSupport ?? Connections.VersionSupport.Kafka10;
     RequestTimeout           = requestTimeout ?? TimeSpan.FromSeconds(Defaults.RequestTimeoutSeconds);
     ReadBufferSize           = readBufferSize.GetValueOrDefault(Defaults.BufferSize);
     WriteBufferSize          = writeBufferSize.GetValueOrDefault(Defaults.BufferSize);
     IsTcpKeepalive           = isTcpKeepalive ?? Defaults.IsTcpKeepalive;
     Encoders                 = Defaults.Encoders(encoders);
     SslConfiguration         = sslConfiguration;
     OnDisconnected           = onDisconnected;
     OnConnecting             = onConnecting;
     OnConnected              = onConnected;
     OnWriting                = onWriting;
     OnWritingBytes           = onWritingBytes;
     OnWroteBytes             = onWroteBytes;
     OnWritten                = onWritten;
     OnWriteFailed            = onWriteFailed;
     OnReading                = onReading;
     OnReadingBytes           = onReadingBytes;
     OnReadBytes              = onReadBytes;
     OnRead                   = onRead;
     OnReadFailed             = onReadFailed;
     OnProduceRequestMessages = onProduceRequestMessages;
 }
コード例 #4
0
        /// <summary>
        /// Configuration for the tcp connection.
        /// </summary>
        /// <param name="connectionRetry">Retry details for (re)establishing the connection.</param>
        /// <param name="versionSupport">Support for different protocol versions for Kakfa requests and responses.</param>
        /// <param name="requestTimeout">The maximum time to wait for requests.</param>
        /// <param name="encoders">Custom Encoding support for different protocol types</param>
        /// <param name="sslConfiguration">Configuration for SSL encrypted communication</param>
        /// <param name="onDisconnected">Triggered when the tcp socket is disconnected.</param>
        /// <param name="onConnecting">Triggered when the tcp socket is connecting.</param>
        /// <param name="onConnected">Triggered after the tcp socket is successfully connected.</param>
        /// <param name="onWriteEnqueued">Triggered after enqueing async write task for writing to the tcp stream.</param>
        /// <param name="onWriting">Triggered when writing to the tcp stream.</param>
        /// <param name="onWritten">Triggered after having successfully written to the tcp stream.</param>
        /// <param name="onWriteFailed">Triggered after failing to write to the tcp stream.</param>
        /// <param name="onReading">Triggered when starting to read a message's bytes from the tcp stream.</param>
        /// <param name="onReadingChunk">Triggered when reading a chunk of bytes from the tcp stream.</param>
        /// <param name="onReadChunk">Triggered after successfully reading a chunk of bytes from the tcp stream.</param>
        /// <param name="onRead">Triggered after having successfully read a message's bytes from the tcp stream.</param>
        /// <param name="onReadFailed">Triggered after failing to read from the tcp stream.</param>
        /// <param name="onProduceRequestMessages">Triggered when encoding ProduceRequest messages.</param>
        public ConnectionConfiguration(
            IRetry connectionRetry         = null,
            IVersionSupport versionSupport = null,
            TimeSpan?requestTimeout        = null,
            IEnumerable <IProtocolTypeEncoder> encoders = null,
            ISslConfiguration sslConfiguration          = null,
            ConnectError onDisconnected = null,
            Connecting onConnecting     = null,
            Connecting onConnected      = null,
            Writing onWriteEnqueued     = null,
            Writing onWriting           = null,
            WriteSuccess onWritten      = null,
            WriteError onWriteFailed    = null,
            Reading onReading           = null,
            ReadingChunk onReadingChunk = null,
            ReadChunk onReadChunk       = null,
            Read onRead            = null,
            ReadError onReadFailed = null,
            ProduceRequestMessages onProduceRequestMessages = null
            )
        {
            ConnectionRetry = connectionRetry ?? Defaults.ConnectionRetry();
            VersionSupport  = versionSupport ?? Connections.VersionSupport.Kafka8;
            RequestTimeout  = requestTimeout ?? TimeSpan.FromSeconds(Defaults.RequestTimeoutSeconds);
            Encoders        = encoders != null
                ? encoders.ToImmutableDictionary(e => e.Type)
                : ImmutableDictionary <string, IProtocolTypeEncoder> .Empty;

            SslConfiguration         = sslConfiguration;
            OnDisconnected           = onDisconnected;
            OnConnecting             = onConnecting;
            OnConnected              = onConnected;
            OnWriteEnqueued          = onWriteEnqueued;
            OnWriting                = onWriting;
            OnWritten                = onWritten;
            OnWriteFailed            = onWriteFailed;
            OnReading                = onReading;
            OnReadingChunk           = onReadingChunk;
            OnReadChunk              = onReadChunk;
            OnRead                   = onRead;
            OnReadFailed             = onReadFailed;
            OnProduceRequestMessages = onProduceRequestMessages;
        }
コード例 #5
0
        public static string DefaultClientId = "KC"; // This gets sent on every request, so may as well shorten "KafkaClient" to "KC"

        public static RequestContext Copy(IRequestContext original, int correlationId, short?version = null, string clientId = null, IImmutableDictionary <string, IMembershipEncoder> encoders = null, string protocolType = null, ProduceRequestMessages onProduceRequestMessages = null)
        {
            return(new RequestContext(correlationId, original?.ApiVersion ?? version, original?.ClientId ?? clientId, original?.Encoders ?? encoders, original?.ProtocolType ?? protocolType, original?.OnProduceRequestMessages ?? onProduceRequestMessages));
        }