Class: Gcpc::Subscriber

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gcpc/subscriber.rb,
lib/gcpc/subscriber/engine.rb,
lib/gcpc/subscriber/base_handler.rb,
lib/gcpc/subscriber/handle_engine.rb,
lib/gcpc/subscriber/default_logger.rb,
lib/gcpc/subscriber/base_interceptor.rb,
lib/gcpc/subscriber/subscription_client.rb

Defined Under Namespace

Classes: BaseHandler, BaseInterceptor, Engine, HandleEngine, SubscriptionClient

Constant Summary collapse

DefaultLogger =
Logger.new(STDOUT)

Instance Method Summary collapse

Constructor Details

#initialize(project_id:, subscription:, credentials: nil, emulator_host: nil, interceptors: [], ack_immediately: false, logger: DefaultLogger) ⇒ Subscriber

Returns a new instance of Subscriber.

Parameters:

  • project_id (String)
  • subscription (String)
  • credentials (String, Google::Cloud::Pubsub::Credentials, nil) (defaults to: nil)

    Path of keyfile or Google::Cloud::Pubsub::Credentials or nil.

  • emulator_host (String, nil) (defaults to: nil)

    Emulator’s host or nil.

  • interceptors (<#handle, #on_error>) (defaults to: [])
  • ack_immediately (bool) (defaults to: false)
  • logger (Logger) (defaults to: DefaultLogger)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gcpc/subscriber.rb', line 17

def initialize(
  project_id:,
  subscription:,
  credentials:     nil,
  emulator_host:   nil,
  interceptors:    [],
  ack_immediately: false,
  logger:          DefaultLogger
)
  subscription_client = SubscriptionClient.new(
    project_id:        project_id,
    subscription_name: subscription,
    credentials:       credentials,
    emulator_host:     emulator_host,
  )

  s = subscription_client.get
  if s.nil?
    raise "Getting subscription \"#{subscription}\" from project \"#{project_id}\" failed! The subscription \"#{subscription}\" does not exist!"
  end

  @engine = Engine.new(
    subscription:    s,
    interceptors:    interceptors,
    ack_immediately: ack_immediately,
    logger:          logger,
  )
end