Class: Gcpc::Publisher::TopicClient
- Inherits:
-
Object
- Object
- Gcpc::Publisher::TopicClient
- Defined in:
- lib/gcpc/publisher/topic_client.rb
Constant Summary collapse
- DEFAULT_CONNECT_TIMEOUT =
5
Instance Method Summary collapse
- #get ⇒ Google::Cloud::Pubsub::Topic
-
#initialize(project_id:, topic_name:, credentials:, emulator_host:, connect_timeout: DEFAULT_CONNECT_TIMEOUT) ⇒ TopicClient
constructor
A new instance of TopicClient.
Constructor Details
#initialize(project_id:, topic_name:, credentials:, emulator_host:, connect_timeout: DEFAULT_CONNECT_TIMEOUT) ⇒ TopicClient
Returns a new instance of TopicClient.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gcpc/publisher/topic_client.rb', line 10 def initialize(project_id:, topic_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 @topic_name = topic_name @connect_timeout = connect_timeout end |
Instance Method Details
#get ⇒ Google::Cloud::Pubsub::Topic
22 23 24 25 26 27 28 29 30 |
# File 'lib/gcpc/publisher/topic_client.rb', line 22 def get t = nil Timeout.timeout(@connect_timeout) do t = @project.topic(@topic_name) end t rescue Timeout::Error => e raise "Getting topic \"#{@topic_name}\" from project \"#{@project.project_id}\" timed out!" end |