Class: Google::Cloud::Pubsub::Topic
- Inherits:
-
Object
- Object
- Google::Cloud::Pubsub::Topic
- Defined in:
- lib/google/cloud/pubsub/topic.rb,
lib/google/cloud/pubsub/topic/list.rb,
lib/google/cloud/pubsub/topic/publisher.rb
Overview
Topic
A named resource to which messages are published.
Defined Under Namespace
Instance Method Summary collapse
-
#delete ⇒ Boolean
Permanently deletes the topic.
-
#exists? ⇒ Boolean
Determines whether the topic exists in the Pub/Sub service.
-
#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 access control policy for this topic.
-
#policy=(new_policy) ⇒ Object
Updates the Cloud 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) ⇒ Google::Cloud::Pubsub::Subscription
(also: #create_subscription, #new_subscription)
Creates a new Subscription object on the current Topic.
-
#subscription(subscription_name, skip_lookup: nil) ⇒ Google::Cloud::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 access control policy.
Instance Method Details
#delete ⇒ Boolean
Permanently deletes the topic.
86 87 88 89 90 |
# File 'lib/google/cloud/pubsub/topic.rb', line 86 def delete ensure_service! service.delete_topic name true end |
#exists? ⇒ Boolean
Determines whether the topic exists in the Pub/Sub service.
424 425 426 427 428 429 430 431 |
# File 'lib/google/cloud/pubsub/topic.rb', line 424 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 |
#name ⇒ Object
The name of the topic in the form of "/projects/project-identifier/topics/topic-name".
69 70 71 |
# File 'lib/google/cloud/pubsub/topic.rb', line 69 def name @grpc ? @grpc.name : @name end |
#policy(force: nil) {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this topic.
326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/google/cloud/pubsub/topic.rb', line 326 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 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.
366 367 368 369 370 |
# File 'lib/google/cloud/pubsub/topic.rb', line 366 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.
269 270 271 272 273 274 275 |
# File 'lib/google/cloud/pubsub/topic.rb', line 269 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) ⇒ Google::Cloud::Pubsub::Subscription Also known as: create_subscription, new_subscription
Creates a new Subscription object on the current Topic.
127 128 129 130 131 132 |
# File 'lib/google/cloud/pubsub/topic.rb', line 127 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) ⇒ Google::Cloud::Pubsub::Subscription? Also known as: get_subscription, find_subscription
Retrieves subscription by name.
166 167 168 169 170 171 172 173 |
# File 'lib/google/cloud/pubsub/topic.rb', line 166 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 Google::Cloud::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.
209 210 211 212 213 214 |
# File 'lib/google/cloud/pubsub/topic.rb', line 209 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 access control policy.
405 406 407 408 409 410 411 |
# File 'lib/google/cloud/pubsub/topic.rb', line 405 def * = Array().flatten = Array().flatten ensure_service! grpc = service. name, grpc. end |