public DataPayload(byte[] buffer, int correlationId = 0, ApiKeyRequestType apiKey = ApiKeyRequestType.Produce, int messageCount = 0) { Buffer = buffer; CorrelationId = correlationId; ApiKey = apiKey; MessageCount = messageCount; }
public AsyncRequestItem(int correlationId, ApiKeyRequestType requestType, TimeSpan timeout) { CorrelationId = correlationId; Timeout = timeout; RequestType = requestType; ReceiveTask = new TaskCompletionSource <byte[]>(); }
/// <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; }
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)); } }
protected Request(ApiKeyRequestType apiKey, bool expectResponse = true, string protocolType = null) { ApiKey = apiKey; ExpectResponse = expectResponse; ProtocolType = protocolType; }
/// <summary> /// Writes a key to the underlying stream. /// </summary> public void Write(ApiKeyRequestType apiKey) { this.Write((short)apiKey); }
public short?GetVersion(ApiKeyRequestType requestType) { short version; return(_versionSupport.TryGetValue(requestType, out version) ? version : (short?)null); }
public FetchOutOfRangeException(FetchRequest.Topic topic, ApiKeyRequestType apiKey, ErrorResponseCode errorCode, string message = null) : base(apiKey, errorCode, message) { Topic = topic; }
public VersionSupport(ApiKeyRequestType apiKey, short minVersion, short maxVersion) { ApiKey = apiKey; MinVersion = minVersion; MaxVersion = maxVersion; }
public void Failure(ApiKeyRequestType type, TimeSpan duration) { RequestsFailed.AddOrUpdate(type, 1, (key, old) => old + 1); Interlocked.Add(ref _duration, duration.Ticks); }
public void Attempt(ApiKeyRequestType type) { RequestsAttempted.AddOrUpdate(type, 1, (key, old) => old + 1); }
protected BaseRequest(ApiKeyRequestType apiKey, short apiVersion = 0) { this.apiKey = apiKey; _apiVersion = apiVersion; }
public RequestException(ApiKeyRequestType apiKey, ErrorResponseCode errorCode, string message = null) : base(message ?? $"Kafka returned {errorCode} for {apiKey} request") { ApiKey = apiKey; ErrorCode = errorCode; }