public ConnectionHandler(ClientConfigurationData conf, HandlerState state, Backoff backoff, IActorRef connection) { _state = state; _connection = connection; _backoff = backoff; _log = Context.System.Log; _actorContext = Context; _conf = conf; Listening(); }
/// <summary> /// calls broker binaryProto-lookup api to get metadata of partitioned-topic. /// /// </summary> private async ValueTask GetPartitionedTopicMetadata(TopicName topicName, TimeSpan opTimeout) { var request = Commands.NewPartitionMetadataRequest(topicName.ToString(), _requestId); var payload = new Payload(request, _requestId, "NewPartitionMetadataRequest"); var askResponse = await _clientCnx.Ask <AskResponse>(payload); if (askResponse.Failed) { var e = askResponse.Exception; var nextDelay = Math.Min(_getPartitionedTopicMetadataBackOff.Next(), opTimeout.TotalMilliseconds); var reply = _replyTo; var isLookupThrottling = !PulsarClientException.IsRetriableError(e) || e is PulsarClientException.TooManyRequestsException || e is PulsarClientException.AuthenticationException; if (nextDelay <= 0 || isLookupThrottling) { reply.Tell(new AskResponse(new PulsarClientException.InvalidConfigurationException(e))); _log.Error(e.ToString()); _getPartitionedTopicMetadataBackOff = null; } else { _log.Warning($"[topic: {topicName}] Could not get connection while getPartitionedTopicMetadata -- Will try again in {nextDelay} ms: {e.Message}"); opTimeout.Subtract(TimeSpan.FromMilliseconds(nextDelay)); var id = await _generator.Ask <NewRequestIdResponse>(NewRequestId.Instance); _requestId = id.Id; await GetPartitionedTopicMetadata(topicName, opTimeout); } } var data = askResponse.ConvertTo <LookupDataResult>(); if (data?.Error != ServerError.UnknownError) { _log.Warning($"[{topicName}] failed to get Partitioned metadata : {data.Error}:{data.ErrorMessage}"); _replyTo.Tell(new AskResponse(new PartitionedTopicMetadata(0))); } else { _replyTo.Tell(new AskResponse(new PartitionedTopicMetadata(data.Partitions))); } _getPartitionedTopicMetadataBackOff = null; }
public static Props Prop(ClientConfigurationData conf, HandlerState state, Backoff backoff, IActorRef connection) { return(Props.Create(() => new ConnectionHandler(conf, state, backoff, connection))); }
private void Awaiting() { Receive <SetClient>(c => { //_pulsarClient = c.Client; }); Receive <UpdateServiceUrl>(u => { UpdateServiceUrl(u.ServiceUrl); }); ReceiveAsync <GetBroker>(async b => { try { _replyTo = Sender; await GetCnxAndRequestId(); await GetBroker(b); } catch (Exception e) { _replyTo.Tell(new AskResponse(PulsarClientException.Unwrap(e))); } }); ReceiveAsync <GetPartitionedTopicMetadata>(async p => { try { var opTimeout = _operationTimeout; _replyTo = Sender; _getPartitionedTopicMetadataBackOff = (new BackoffBuilder()).SetInitialTime(TimeSpan.FromMilliseconds(100)).SetMandatoryStop(opTimeout.Multiply(2)).SetMax(TimeSpan.FromMinutes(1)).Create(); await GetCnxAndRequestId(); await GetPartitionedTopicMetadata(p.TopicName, opTimeout); } catch (Exception e) { _replyTo.Tell(new AskResponse(PulsarClientException.Unwrap(e))); } }); ReceiveAsync <GetSchema>(async s => { try { _replyTo = Sender; await GetCnxAndRequestId(); await GetSchema(s.TopicName, s.Version); } catch (Exception e) { _replyTo.Tell(new AskResponse(PulsarClientException.Unwrap(e))); } }); ReceiveAsync <GetTopicsUnderNamespace>(async t => { try { var opTimeout = _operationTimeout; _getTopicsUnderNamespaceBackOff = new BackoffBuilder().SetInitialTime(TimeSpan.FromMilliseconds(100)).SetMandatoryStop(opTimeout.Multiply(2)).SetMax(TimeSpan.FromMinutes(1)).Create(); _replyTo = Sender; await GetCnxAndRequestId(); await GetTopicsUnderNamespace(t.Namespace, t.Mode, opTimeout); } catch (Exception e) { _replyTo.Tell(new AskResponse(PulsarClientException.Unwrap(e))); } }); }