public static BaseCommand ToBaseCommand(this CommandLookupTopic value) { return(new BaseCommand { type = BaseCommand.Type.Lookup, lookupTopic = value }); }
public static BaseCommand AsBaseCommand(this CommandLookupTopic command) { return(new BaseCommand { CommandType = BaseCommand.Type.Lookup, LookupTopic = command }); }
public async Task <BaseCommand> Send(CommandLookupTopic command, CancellationToken cancellationToken) { ThrowIfDisposed(); Task <BaseCommand>?responseTask; using (await _lock.Lock(cancellationToken).ConfigureAwait(false)) { responseTask = _channelManager.Outgoing(command); var sequence = Serializer.Serialize(command.AsBaseCommand()); await _stream.Send(sequence).ConfigureAwait(false); } return(await responseTask.ConfigureAwait(false)); }
public static ReadOnlySequence <byte> NewLookup(string topic, string listenerName, bool authoritative, long requestId) { var lookupTopic = new CommandLookupTopic { Topic = topic, RequestId = (ulong)requestId, Authoritative = authoritative }; if (!string.IsNullOrWhiteSpace(listenerName)) { lookupTopic.AdvertisedListenerName = listenerName; } return(Serializer.Serialize(lookupTopic.ToBaseCommand())); }
public async ValueTask <IConnection> FindConnectionForTopic(string topic, CancellationToken cancellationToken) { var lookup = new CommandLookupTopic { Topic = topic, Authoritative = false, AdvertisedListenerName = _listenerName }; var physicalUrl = _serviceUrl; while (true) { var connection = await GetConnection(physicalUrl, cancellationToken).ConfigureAwait(false); var response = await connection.Send(lookup, cancellationToken).ConfigureAwait(false); response.Expect(BaseCommand.Type.LookupResponse); if (response.LookupTopicResponse.Response == CommandLookupTopicResponse.LookupType.Failed) { response.LookupTopicResponse.Throw(); } lookup.Authoritative = response.LookupTopicResponse.Authoritative; var lookupResponseServiceUrl = new Uri(GetBrokerServiceUrl(response.LookupTopicResponse)); if (response.LookupTopicResponse.Response == CommandLookupTopicResponse.LookupType.Redirect || !response.LookupTopicResponse.Authoritative) { physicalUrl = lookupResponseServiceUrl; continue; } if (response.LookupTopicResponse.ProxyThroughServiceUrl) { var url = new PulsarUrl(physicalUrl, lookupResponseServiceUrl); return(await GetConnection(url, cancellationToken).ConfigureAwait(false)); } // LookupType is 'Connect', ServiceUrl is local and response is authoritative. Assume the Pulsar server is a standalone docker. return(lookupResponseServiceUrl.IsLoopback ? connection : await GetConnection(lookupResponseServiceUrl, cancellationToken).ConfigureAwait(false)); } }
public async Task <Connection> FindConnectionForTopic(string topic, CancellationToken cancellationToken) { var lookup = new CommandLookupTopic { Topic = topic, Authoritative = false }; var serviceUrl = _serviceUrl; while (true) { var connection = await CreateConnection(serviceUrl, cancellationToken); var response = await connection.Send(lookup); response.Expect(BaseCommand.Type.LookupResponse); if (response.LookupTopicResponse.Response == CommandLookupTopicResponse.LookupType.Failed) { response.LookupTopicResponse.Throw(); } lookup.Authoritative = response.LookupTopicResponse.Authoritative; serviceUrl = new Uri(GetBrokerServiceUrl(response.LookupTopicResponse)); if (response.LookupTopicResponse.Response == CommandLookupTopicResponse.LookupType.Redirect || !response.LookupTopicResponse.Authoritative) { continue; } if (_serviceUrl.IsLoopback) // LookupType is 'Connect', ServiceUrl is local and response is authoritative. Assume the Pulsar server is a standalone docker. { return(connection); } else { return(await CreateConnection(serviceUrl, cancellationToken)); } } }
public Task <BaseCommand> Send(CommandLookupTopic command, CancellationToken cancellationToken) => SendRequestResponse(command.AsBaseCommand(), cancellationToken);
public Task <BaseCommand> Outgoing(CommandLookupTopic command) { command.RequestId = _requestId.FetchNext(); return(_requests.CreateTask(StandardRequest.WithRequestId(command.RequestId))); }
public Task <BaseCommand> Outgoing(CommandLookupTopic command) => _requestResponseHandler.Outgoing(command);
public async Task <BaseCommand> Send(CommandLookupTopic command) => await SendRequestResponse(command.AsBaseCommand());