Class: Gcloud::Pubsub::Topic
- Inherits:
-
Object
- Object
- Gcloud::Pubsub::Topic
- Defined in:
- lib/gcloud/pubsub/topic.rb,
lib/gcloud/pubsub/topic/list.rb,
lib/gcloud/pubsub/topic/publisher.rb
Overview
# Topic
A named resource to which messages are published.
Defined Under Namespace
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#delete ⇒ Boolean
Permanently deletes the topic.
-
#exists? ⇒ Boolean
Determines whether the topic exists in the Pub/Sub service.
-
#initialize ⇒ Topic
constructor
A new instance of Topic.
-
#lazy? ⇒ Boolean
Determines whether the topic object was created with an HTTP call.
-
#name ⇒ Object
The name of the topic in the form of “/projects/project-identifier/topics/topic-name”.
-
#policy(force: nil) {|policy| ... } ⇒ Policy
Gets the [Cloud IAM](cloud.google.com/iam/) access control policy for this topic.
-
#policy=(new_policy) ⇒ Object
Updates the [Cloud IAM](cloud.google.com/iam/) access control policy for this topic.
-
#publish(data = nil, attributes = {}) {|publisher| ... } ⇒ Message+
Publishes one or more messages to the topic.
-
#subscribe(subscription_name, deadline: nil, endpoint: nil) ⇒ Gcloud::Pubsub::Subscription
(also: #create_subscription, #new_subscription)
Creates a new Subscription object on the current Topic.
-
#subscription(subscription_name, skip_lookup: nil) ⇒ Gcloud::Pubsub::Subscription?
(also: #get_subscription, #find_subscription)
Retrieves subscription by name.
-
#subscriptions(token: nil, max: nil) ⇒ Array<Subscription>
(also: #find_subscriptions, #list_subscriptions)
Retrieves a list of subscription names for the given project.
-
#test_permissions(*permissions) ⇒ Array<Strings>
Tests the specified permissions against the [Cloud IAM](cloud.google.com/iam/) access control policy.
Constructor Details
#initialize ⇒ Topic
Returns a new instance of Topic.
49 50 51 52 53 54 |
# File 'lib/gcloud/pubsub/topic.rb', line 49 def initialize @service = nil @grpc = Google::Pubsub::V1::Topic.new @name = nil @exists = nil end |
Instance Attribute Details
#grpc ⇒ Object
45 46 47 |
# File 'lib/gcloud/pubsub/topic.rb', line 45 def grpc @grpc end |
#service ⇒ Object
41 42 43 |
# File 'lib/gcloud/pubsub/topic.rb', line 41 def service @service end |
Class Method Details
.from_grpc(grpc, service) ⇒ Object
477 478 479 480 481 482 |
# File 'lib/gcloud/pubsub/topic.rb', line 477 def self.from_grpc grpc, service new.tap do |f| f.grpc = grpc f.service = service end end |
.new_lazy(name, service, options = {}) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/gcloud/pubsub/topic.rb', line 58 def self.new_lazy name, service, = {} new.tap do |t| t.grpc = nil t.service = service t.instance_variable_set "@name", service.topic_path(name, ) end end |
Instance Method Details
#delete ⇒ Boolean
Permanently deletes the topic.
87 88 89 90 91 |
# File 'lib/gcloud/pubsub/topic.rb', line 87 def delete ensure_service! service.delete_topic name true end |
#exists? ⇒ Boolean
Determines whether the topic exists in the Pub/Sub service.
449 450 451 452 453 454 455 456 |
# File 'lib/gcloud/pubsub/topic.rb', line 449 def exists? # Always true if we have a grpc object return true unless @grpc.nil? # If we have a value, return it return @exists unless @exists.nil? ensure_grpc! @exists = !@grpc.nil? end |
#lazy? ⇒ Boolean
Determines whether the topic object was created with an HTTP call.
471 472 473 |
# File 'lib/gcloud/pubsub/topic.rb', line 471 def lazy? @grpc.nil? end |
#name ⇒ Object
The name of the topic in the form of “/projects/project-identifier/topics/topic-name”.
69 70 71 |
# File 'lib/gcloud/pubsub/topic.rb', line 69 def name @grpc ? @grpc.name : @name end |
#policy(force: nil) {|policy| ... } ⇒ Policy
Gets the [Cloud IAM](cloud.google.com/iam/) access control policy for this topic.
348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/gcloud/pubsub/topic.rb', line 348 def policy force: nil @policy = nil if force || block_given? @policy ||= begin ensure_service! grpc = service.get_topic_policy name Policy.from_grpc grpc end return @policy unless block_given? p = @policy.deep_dup yield p self.policy = p end |
#policy=(new_policy) ⇒ Object
Updates the [Cloud IAM](cloud.google.com/iam/) access control policy for this topic. The policy should be read from #policy. See Policy for an explanation of the policy ‘etag` property and how to modify policies.
You can also update the policy by passing a block to #policy, which will call this method internally after the block completes.
389 390 391 392 393 |
# File 'lib/gcloud/pubsub/topic.rb', line 389 def policy= new_policy ensure_service! grpc = service.set_topic_policy name, new_policy.to_grpc @policy = Policy.from_grpc grpc end |
#publish(data = nil, attributes = {}) {|publisher| ... } ⇒ Message+
Publishes one or more messages to the topic.
290 291 292 293 294 295 296 |
# File 'lib/gcloud/pubsub/topic.rb', line 290 def publish data = nil, attributes = {} ensure_service! publisher = Publisher.new data, attributes yield publisher if block_given? return nil if publisher..count.zero? publisher end |
#subscribe(subscription_name, deadline: nil, endpoint: nil) ⇒ Gcloud::Pubsub::Subscription Also known as: create_subscription, new_subscription
Creates a new Subscription object on the current Topic.
140 141 142 143 144 145 |
# File 'lib/gcloud/pubsub/topic.rb', line 140 def subscribe subscription_name, deadline: nil, endpoint: nil ensure_service! = { deadline: deadline, endpoint: endpoint } grpc = service.create_subscription name, subscription_name, Subscription.from_grpc grpc, service end |
#subscription(subscription_name, skip_lookup: nil) ⇒ Gcloud::Pubsub::Subscription? Also known as: get_subscription, find_subscription
Retrieves subscription by name.
181 182 183 184 185 186 187 188 |
# File 'lib/gcloud/pubsub/topic.rb', line 181 def subscription subscription_name, skip_lookup: nil ensure_service! return Subscription.new_lazy subscription_name, service if skip_lookup grpc = service.get_subscription subscription_name Subscription.from_grpc grpc, service rescue Gcloud::NotFoundError nil end |
#subscriptions(token: nil, max: nil) ⇒ Array<Subscription> Also known as: find_subscriptions, list_subscriptions
Retrieves a list of subscription names for the given project.
226 227 228 229 230 231 |
# File 'lib/gcloud/pubsub/topic.rb', line 226 def subscriptions token: nil, max: nil ensure_service! = { token: token, max: max } grpc = service.list_topics_subscriptions name, Subscription::List.from_topic_grpc grpc, service, name, max end |
#test_permissions(*permissions) ⇒ Array<Strings>
Tests the specified permissions against the [Cloud IAM](cloud.google.com/iam/) access control policy.
429 430 431 432 433 434 435 |
# File 'lib/gcloud/pubsub/topic.rb', line 429 def * = Array().flatten = Array().flatten ensure_service! grpc = service. name, grpc. end |