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
Overview
Topic
A named resource to which messages are published.
Defined Under Namespace
Classes: List
Instance Method Summary collapse
-
#async_publisher ⇒ AsyncPublisher
AsyncPublisher object used to publish multiple messages in batches.
-
#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 {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this topic.
-
#publish(data = nil, attributes = {}) {|batch| ... } ⇒ Message+
Publishes one or more messages to the topic.
-
#publish_async(data = nil, attributes = {}) {|result| ... } ⇒ Object
Publishes a message asynchonously to the topic.
-
#subscribe(subscription_name, deadline: nil, retain_acked: false, retention: 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.
-
#update_policy(new_policy) ⇒ Policy
(also: #policy=)
Updates the Cloud IAM access control policy for this topic.
Instance Method Details
#async_publisher ⇒ AsyncPublisher
AsyncPublisher object used to publish multiple messages in batches.
80 81 82 |
# File 'lib/google/cloud/pubsub/topic.rb', line 80 def async_publisher @async_publisher end |
#delete ⇒ Boolean
Permanently deletes the topic.
104 105 106 107 108 |
# File 'lib/google/cloud/pubsub/topic.rb', line 104 def delete ensure_service! service.delete_topic name true end |
#exists? ⇒ Boolean
Determines whether the topic exists in the Pub/Sub service.
506 507 508 509 510 511 512 513 514 515 |
# File 'lib/google/cloud/pubsub/topic.rb', line 506 def exists? # Always true if the object is not set as lazy return true unless lazy? # If we have a value, return it return @exists unless @exists.nil? ensure_grpc! @exists = true rescue Google::Cloud::NotFoundError @exists = false end |
#name ⇒ Object
The name of the topic in the form of "/projects/project-identifier/topics/topic-name".
87 88 89 |
# File 'lib/google/cloud/pubsub/topic.rb', line 87 def name @grpc.name end |
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this topic.
409 410 411 412 413 414 415 416 |
# File 'lib/google/cloud/pubsub/topic.rb', line 409 def policy ensure_service! grpc = service.get_topic_policy name policy = Policy.from_grpc grpc return policy unless block_given? yield policy update_policy policy end |
#publish(data = nil, attributes = {}) {|batch| ... } ⇒ Message+
Publishes one or more messages to the topic.
The message payload must not be empty; it must contain either a non-empty data field, or at least one attribute.
309 310 311 312 313 314 315 |
# File 'lib/google/cloud/pubsub/topic.rb', line 309 def publish data = nil, attributes = {} ensure_service! batch = BatchPublisher.new data, attributes yield batch if block_given? return nil if batch..count.zero? batch end |
#publish_async(data = nil, attributes = {}) {|result| ... } ⇒ Object
Publishes a message asynchonously to the topic.
The message payload must not be empty; it must contain either a non-empty data field, or at least one attribute.
368 369 370 371 372 373 |
# File 'lib/google/cloud/pubsub/topic.rb', line 368 def publish_async data = nil, attributes = {}, &block ensure_service! @async_publisher ||= AsyncPublisher.new(name, service, @async_opts) @async_publisher.publish data, attributes, &block end |
#subscribe(subscription_name, deadline: nil, retain_acked: false, retention: nil, endpoint: nil) ⇒ Google::Cloud::Pubsub::Subscription Also known as: create_subscription, new_subscription
Creates a new Subscription object on the current Topic.
156 157 158 159 160 161 162 163 |
# File 'lib/google/cloud/pubsub/topic.rb', line 156 def subscribe subscription_name, deadline: nil, retain_acked: false, retention: nil, endpoint: nil ensure_service! = { deadline: deadline, retain_acked: retain_acked, retention: retention, 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.
200 201 202 203 204 205 206 207 |
# File 'lib/google/cloud/pubsub/topic.rb', line 200 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.
243 244 245 246 247 248 |
# File 'lib/google/cloud/pubsub/topic.rb', line 243 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.
487 488 489 490 491 492 493 |
# File 'lib/google/cloud/pubsub/topic.rb', line 487 def * = Array().flatten = Array().flatten ensure_service! grpc = service. name, grpc. end |
#update_policy(new_policy) ⇒ Policy Also known as: policy=
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.
447 448 449 450 451 |
# File 'lib/google/cloud/pubsub/topic.rb', line 447 def update_policy new_policy ensure_service! grpc = service.set_topic_policy name, new_policy.to_grpc @policy = Policy.from_grpc grpc end |