Example #1
0
 public DataPayload(byte[] buffer, int correlationId = 0, ApiKeyRequestType apiKey = ApiKeyRequestType.Produce, int messageCount = 0)
 {
     Buffer        = buffer;
     CorrelationId = correlationId;
     ApiKey        = apiKey;
     MessageCount  = messageCount;
 }
Example #2
0
 public AsyncRequestItem(int correlationId, ApiKeyRequestType requestType, TimeSpan timeout)
 {
     CorrelationId = correlationId;
     Timeout       = timeout;
     RequestType   = requestType;
     ReceiveTask   = new TaskCompletionSource <byte[]>();
 }
Example #3
0
        /// <inheritdoc />
        protected GroupRequest(ApiKeyRequestType apiKey, string groupId, string memberId, int groupGenerationId = 0, bool expectResponse = true) : base(apiKey, expectResponse)
        {
            if (string.IsNullOrEmpty(groupId))
            {
                throw new ArgumentNullException(nameof(groupId));
            }

            GroupId           = groupId;
            MemberId          = memberId;
            GroupGenerationId = groupGenerationId;
        }
Example #4
0
        private async Task <short> GetVersionAsync(ApiKeyRequestType requestType, CancellationToken cancellationToken)
        {
            if (!_configuration.VersionSupport.IsDynamic)
            {
                return(_configuration.VersionSupport.GetVersion(requestType).GetValueOrDefault());
            }

            using (await _versionSupportLock.ReaderLockAsync(cancellationToken).ConfigureAwait(false)) {
                if (_versionSupport != null)
                {
                    return(_versionSupport.GetVersion(requestType).GetValueOrDefault());
                }
            }
            using (await _versionSupportLock.WriterLockAsync(cancellationToken).ConfigureAwait(false)) {
                return(await _configuration.ConnectionRetry.AttemptAsync(
                           async (attempt, timer) => {
                    var response = await SendAsync(new ApiVersionsRequest(), cancellationToken, new RequestContext(version: 0)).ConfigureAwait(false);
                    if (response.ErrorCode.IsRetryable())
                    {
                        return RetryAttempt <short> .Retry;
                    }
                    if (!response.ErrorCode.IsSuccess())
                    {
                        return RetryAttempt <short> .Abort;
                    }

                    var supportedVersions = response.SupportedVersions.ToImmutableDictionary(
                        _ => _.ApiKey,
                        _ => _.MaxVersion);
                    _versionSupport = new VersionSupport(supportedVersions);
                    return new RetryAttempt <short>(_versionSupport.GetVersion(requestType).GetValueOrDefault());
                },
                           (attempt, timer) => _log.Debug(() => LogEvent.Create($"Retrying {nameof(GetVersionAsync)} attempt {attempt}")),
                           attempt => _versionSupport = _configuration.VersionSupport,
                           exception => _log.Error(LogEvent.Create(exception)),
                           cancellationToken));
            }
        }
Example #5
0
 protected Request(ApiKeyRequestType apiKey, bool expectResponse = true, string protocolType = null)
 {
     ApiKey         = apiKey;
     ExpectResponse = expectResponse;
     ProtocolType   = protocolType;
 }
Example #6
0
 /// <summary>
 /// Writes a key to the underlying stream.
 /// </summary>
 public void Write(ApiKeyRequestType apiKey)
 {
     this.Write((short)apiKey);
 }
Example #7
0
        public short?GetVersion(ApiKeyRequestType requestType)
        {
            short version;

            return(_versionSupport.TryGetValue(requestType, out version) ? version : (short?)null);
        }
Example #8
0
 public FetchOutOfRangeException(FetchRequest.Topic topic, ApiKeyRequestType apiKey, ErrorResponseCode errorCode, string message = null)
     : base(apiKey, errorCode, message)
 {
     Topic = topic;
 }
Example #9
0
 public VersionSupport(ApiKeyRequestType apiKey, short minVersion, short maxVersion)
 {
     ApiKey     = apiKey;
     MinVersion = minVersion;
     MaxVersion = maxVersion;
 }
Example #10
0
 public void Failure(ApiKeyRequestType type, TimeSpan duration)
 {
     RequestsFailed.AddOrUpdate(type, 1, (key, old) => old + 1);
     Interlocked.Add(ref _duration, duration.Ticks);
 }
Example #11
0
 public void Attempt(ApiKeyRequestType type)
 {
     RequestsAttempted.AddOrUpdate(type, 1, (key, old) => old + 1);
 }
Example #12
0
 /// <summary>
 /// Writes a key to the underlying stream.
 /// </summary>
 public void Write(ApiKeyRequestType apiKey)
 {
     this.Write((short)apiKey);
 }
Example #13
0
 protected BaseRequest(ApiKeyRequestType apiKey, short apiVersion = 0)
 {
     this.apiKey = apiKey;
     _apiVersion = apiVersion;
 }
Example #14
0
 public RequestException(ApiKeyRequestType apiKey, ErrorResponseCode errorCode, string message = null)
     : base(message ?? $"Kafka returned {errorCode} for {apiKey} request")
 {
     ApiKey    = apiKey;
     ErrorCode = errorCode;
 }