Class: Gcpc::Publisher

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gcpc/publisher.rb,
lib/gcpc/publisher/engine.rb,
lib/gcpc/publisher/topic_client.rb,
lib/gcpc/publisher/base_interceptor.rb,
lib/gcpc/publisher/engine/batch_engine.rb,
lib/gcpc/publisher/engine/chained_interceptor.rb

Defined Under Namespace

Classes: BaseInterceptor, Engine, TopicClient

Instance Method Summary collapse

Constructor Details

#initialize(project_id:, topic:, credentials: nil, emulator_host: nil, interceptors: []) ⇒ Publisher

Returns a new instance of Publisher.

Parameters:

  • project_id (String)
  • topic (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 (<#publish>) (defaults to: [])


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gcpc/publisher.rb', line 13

def initialize(
  project_id:,
  topic:,
  credentials:   nil,
  emulator_host: nil,
  interceptors:  []
)
  topic_client = TopicClient.new(
    project_id:    project_id,
    topic_name:    topic,
    credentials:   credentials,
    emulator_host: emulator_host,
  )

  t = topic_client.get
  if t.nil?
    raise "Getting topic \"#{topic}\" from project \"#{project_id}\" failed! The topic \"#{topic}\" does not exist!"
  end

  @engine = Engine.new(
    topic:        t,
    interceptors: interceptors,
  )
end