Class: Pulsar::Internal::LookupService

Inherits:
Object
  • Object
show all
Defined in:
lib/pulsar/internal/lookup_service.rb

Overview

Resolves the broker service URL that owns a topic.

Instance Method Summary collapse

Constructor Details

#initialize(connection:, operation_timeout:) ⇒ LookupService

Returns a new instance of LookupService.



7
8
9
10
# File 'lib/pulsar/internal/lookup_service.rb', line 7

def initialize(connection:, operation_timeout:)
  @connection = connection
  @operation_timeout = operation_timeout
end

Instance Method Details

#lookup(topic) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pulsar/internal/lookup_service.rb', line 12

def lookup(topic)
  request_id = @connection.next_request_id
  response = @connection.request(
    CommandFactory.lookup(topic: topic, request_id: request_id),
    timeout: @operation_timeout
  )

  raise BrokerError, "lookup failed: #{response.type}" unless response.type == :LOOKUP_RESPONSE

  lookup = response.lookupTopicResponse
  raise BrokerError, "lookup failed: #{lookup.message}" unless lookup.response == :Connect

  lookup.brokerServiceUrl
end