Class: Gcpc::Subscriber::SubscriptionClient

Inherits:
Object
  • Object
show all
Defined in:
lib/gcpc/subscriber/subscription_client.rb

Constant Summary collapse

DEFAULT_CONNECT_TIMEOUT =
5

Instance Method Summary collapse

Constructor Details

#initialize(project_id:, subscription_name:, credentials:, emulator_host:, connect_timeout: DEFAULT_CONNECT_TIMEOUT) ⇒ SubscriptionClient

Returns a new instance of SubscriptionClient.

Parameters:

  • project_id (String)
  • subscription_name (String)
  • (Google::Cloud::Pubsub::Credentials, String, nil)
  • emulator_host (String, nil)


12
13
14
15
16
17
18
19
20
21
# File 'lib/gcpc/subscriber/subscription_client.rb', line 12

def initialize(project_id:, subscription_name:, credentials:, emulator_host:, connect_timeout: DEFAULT_CONNECT_TIMEOUT)
  project = Google::Cloud::Pubsub.new(
    project_id:    project_id,
    credentials:   credentials,
    emulator_host: emulator_host,
  )
  @project           = project
  @subscription_name = subscription_name
  @connect_timeout   = connect_timeout
end

Instance Method Details

#getGoogle::Cloud::Pubsub::Subscription

Returns:

  • (Google::Cloud::Pubsub::Subscription)


24
25
26
27
28
29
30
31
32
# File 'lib/gcpc/subscriber/subscription_client.rb', line 24

def get
  t = nil
  Timeout.timeout(@connect_timeout) do
    t = @project.subscription(@subscription_name)
  end
  t
rescue Timeout::Error => e
  raise "Getting subscription \"#{@subscription_name}\" from project \"#{@project.project_id}\" timed out!"
end