Class: Google::Cloud::PubSub::Subscription
- Inherits:
-
Object
- Object
- Google::Cloud::PubSub::Subscription
- Defined in:
- lib/google/cloud/pubsub/subscription.rb,
lib/google/cloud/pubsub/subscription/list.rb,
lib/google/cloud/pubsub/subscription/push_config.rb
Overview
Subscription
A named resource representing the stream of messages from a single, specific Topic, to be delivered to the subscribing application.
Defined Under Namespace
Classes: List, PushConfig
Instance Method Summary collapse
-
#acknowledge(*messages) ⇒ Object
(also: #ack)
Acknowledges receipt of a message.
-
#create_snapshot(snapshot_name = nil, labels: nil) ⇒ Google::Cloud::PubSub::Snapshot
(also: #new_snapshot)
Creates a new Snapshot from the subscription.
-
#dead_letter_max_delivery_attempts ⇒ Integer?
Returns the maximum number of delivery attempts for any message in the subscription's dead letter policy if a dead letter policy is configured, otherwise
nil. -
#dead_letter_max_delivery_attempts=(new_dead_letter_max_delivery_attempts) ⇒ Object
Sets the maximum number of delivery attempts for any message in the subscription's dead letter policy.
-
#dead_letter_topic ⇒ Topic?
Returns the Topic to which dead letter messages should be published if a dead letter policy is configured, otherwise
nil. -
#dead_letter_topic=(new_dead_letter_topic) ⇒ Object
Sets the Topic to which dead letter messages for the subscription should be published.
-
#deadline ⇒ Integer
This value is the maximum number of seconds after a subscriber receives a message before the subscriber should acknowledge the message.
-
#deadline=(new_deadline) ⇒ Object
Sets the maximum number of seconds after a subscriber receives a message before the subscriber should acknowledge the message.
-
#delete ⇒ Boolean
Deletes an existing subscription.
-
#detach ⇒ Boolean
Detaches a subscription from its topic.
-
#detached? ⇒ Boolean
Whether the subscription is detached from its topic.
-
#endpoint ⇒ String
Returns the URL locating the endpoint to which messages should be pushed.
-
#endpoint=(new_endpoint) ⇒ Object
Sets the URL locating the endpoint to which messages should be pushed.
-
#exists? ⇒ Boolean
Determines whether the subscription exists in the Pub/Sub service.
-
#expires_in ⇒ Numeric?
The duration (in seconds) for when a subscription expires after the subscription goes inactive.
-
#expires_in=(ttl) ⇒ Object
Sets the duration (in seconds) for when a subscription expires after the subscription goes inactive.
-
#filter ⇒ String
An expression written in the Cloud Pub/Sub filter language.
-
#labels ⇒ Hash
A hash of user-provided labels associated with this subscription.
-
#labels=(new_labels) ⇒ Object
Sets the hash of user-provided labels associated with this subscription.
-
#listen(deadline: nil, message_ordering: nil, streams: nil, inventory: nil, threads: {}) {|received_message| ... } ⇒ Subscriber
Create a Subscriber object that receives and processes messages using the code provided in the callback.
-
#message_ordering? ⇒ Boolean
Whether message ordering has been enabled.
-
#modify_ack_deadline(new_deadline, *messages) ⇒ Object
Modifies the acknowledge deadline for messages.
-
#name ⇒ String
The name of the subscription.
-
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this subscription.
-
#pull(immediate: true, max: 100) ⇒ Array<Google::Cloud::PubSub::ReceivedMessage>
Pulls messages from the server.
-
#push_config {|push_config| ... } ⇒ Subscription::PushConfig
Inspect the Subscription's push configuration settings.
-
#reference? ⇒ Boolean
Determines whether the subscription object was created without retrieving the resource representation from the Pub/Sub service.
-
#reload! ⇒ Google::Cloud::PubSub::Subscription
(also: #refresh!)
Reloads the subscription with current data from the Pub/Sub service.
-
#remove_dead_letter_policy ⇒ Boolean
Removes an existing dead letter policy.
-
#resource? ⇒ Boolean
Determines whether the subscription object was created with a resource representation from the Pub/Sub service.
-
#retain_acked ⇒ Boolean
Indicates whether to retain acknowledged messages.
-
#retain_acked=(new_retain_acked) ⇒ Object
Sets whether to retain acknowledged messages.
-
#retention ⇒ Numeric
How long to retain unacknowledged messages in the subscription's backlog, from the moment a message is published.
-
#retention=(new_retention) ⇒ Object
Sets the message retention duration in seconds.
-
#retry_policy ⇒ RetryPolicy?
A policy that specifies how Cloud Pub/Sub retries message delivery for this subscription.
-
#retry_policy=(new_retry_policy) ⇒ Object
Sets a policy that specifies how Cloud Pub/Sub retries message delivery for this subscription.
-
#seek(snapshot) ⇒ Boolean
Resets the subscription's backlog to a given Snapshot or to a point in time, whichever is provided in the request.
-
#test_permissions(*permissions) ⇒ Array<String>
Tests the specified permissions against the Cloud IAM access control policy.
-
#topic ⇒ Topic
The Topic from which this subscription receives messages.
-
#update_policy(new_policy) ⇒ Policy
(also: #policy=)
Updates the Cloud IAM access control policy for this subscription.
-
#wait_for_messages(max: 100) ⇒ Array<Google::Cloud::PubSub::ReceivedMessage>
Pulls from the server while waiting for messages to become available.
Instance Method Details
#acknowledge(*messages) ⇒ Object Also known as: ack
Acknowledges receipt of a message. After an ack, the Pub/Sub system can remove the message from the subscription. Acknowledging a message whose ack deadline has expired may succeed, although the message may have been sent again. Acknowledging a message more than once will not result in an error. This is only used for messages received via pull.
See also ReceivedMessage#acknowledge!.
1001 1002 1003 1004 1005 1006 1007 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1001 def acknowledge * ack_ids = coerce_ack_ids return true if ack_ids.empty? ensure_service! service.acknowledge name, *ack_ids true end |
#create_snapshot(snapshot_name = nil, labels: nil) ⇒ Google::Cloud::PubSub::Snapshot Also known as: new_snapshot
Creates a new Google::Cloud::PubSub::Snapshot from the subscription. The created snapshot is guaranteed to retain:
- The existing backlog on the subscription. More precisely, this is
defined as the messages in the subscription's backlog that are
unacknowledged upon the successful completion of the
create_snapshotoperation; as well as: - Any messages published to the subscription's topic following the
successful completion of the
create_snapshotoperation.
1091 1092 1093 1094 1095 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1091 def create_snapshot snapshot_name = nil, labels: nil ensure_service! grpc = service.create_snapshot name, snapshot_name, labels: labels Snapshot.from_grpc grpc, service end |
#dead_letter_max_delivery_attempts ⇒ Integer?
Returns the maximum number of delivery attempts for any message in the subscription's dead letter policy if a
dead letter policy is configured, otherwise nil. Dead lettering is done on a best effort basis. The same
message might be dead lettered multiple times. The value must be between 5 and 100.
The number of delivery attempts is defined as 1 + (the sum of number of NACKs and number of times the acknowledgement deadline has been exceeded for the message). A NACK is any call to ModifyAckDeadline with a 0 deadline. Note that client libraries may automatically extend ack_deadlines.
This field will be honored on a best effort basis. If this parameter is nil or 0, a default value of 5
is used.
See also #dead_letter_max_delivery_attempts=, #dead_letter_topic=, #dead_letter_topic and #remove_dead_letter_policy.
Makes an API call to retrieve the value when called on a reference object. See #reference?.
464 465 466 467 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 464 def dead_letter_max_delivery_attempts ensure_grpc! @grpc.dead_letter_policy&.max_delivery_attempts end |
#dead_letter_max_delivery_attempts=(new_dead_letter_max_delivery_attempts) ⇒ Object
Sets the maximum number of delivery attempts for any message in the subscription's dead letter policy. Dead lettering is done on a best effort basis. The same message might be dead lettered multiple times. The value must be between 5 and 100.
The number of delivery attempts is defined as 1 + (the sum of number of NACKs and number of times the acknowledgement deadline has been exceeded for the message). A NACK is any call to ModifyAckDeadline with a 0 deadline. Note that client libraries may automatically extend ack_deadlines.
This field will be honored on a best effort basis. If this parameter is 0, a default value of 5 is used.
The dead letter topic must be set first. See #dead_letter_topic=, #dead_letter_topic and #remove_dead_letter_policy.
498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 498 def dead_letter_max_delivery_attempts= new_dead_letter_max_delivery_attempts ensure_grpc! unless @grpc.dead_letter_policy&.dead_letter_topic # Service error message "3:Invalid resource name given (name=)." does not identify param. raise ArgumentError, "dead_letter_topic is required with dead_letter_max_delivery_attempts" end dead_letter_policy = @grpc.dead_letter_policy || Google::Cloud::PubSub::V1::DeadLetterPolicy.new dead_letter_policy.max_delivery_attempts = new_dead_letter_max_delivery_attempts update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, dead_letter_policy: dead_letter_policy @grpc = service.update_subscription update_grpc, :dead_letter_policy @resource_name = nil end |
#dead_letter_topic ⇒ Topic?
Returns the Topic to which dead letter messages should be published if a dead letter policy is configured,
otherwise nil. Dead lettering is done on a best effort basis. The same message might be dead lettered
multiple times.
See also #dead_letter_topic=, #dead_letter_max_delivery_attempts=, #dead_letter_max_delivery_attempts and #remove_dead_letter_policy.
Makes an API call to retrieve the topic name when called on a reference object. See #reference?.
396 397 398 399 400 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 396 def dead_letter_topic ensure_grpc! return nil unless @grpc.dead_letter_policy Topic.from_name @grpc.dead_letter_policy.dead_letter_topic, service end |
#dead_letter_topic=(new_dead_letter_topic) ⇒ Object
Sets the Topic to which dead letter messages for the subscription should be published. Dead lettering is
done on a best effort basis. The same message might be dead lettered multiple times.
The Cloud Pub/Sub service account associated with the enclosing subscription's parent project (i.e.,
service-\\{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have permission to Publish() to this
topic.
The operation will fail if the topic does not exist. Users should ensure that there is a subscription attached to this topic since messages published to a topic with no subscriptions are lost.
See also #dead_letter_topic, #dead_letter_max_delivery_attempts=, #dead_letter_max_delivery_attempts and #remove_dead_letter_policy.
427 428 429 430 431 432 433 434 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 427 def dead_letter_topic= new_dead_letter_topic ensure_grpc! dead_letter_policy = @grpc.dead_letter_policy || Google::Cloud::PubSub::V1::DeadLetterPolicy.new dead_letter_policy.dead_letter_topic = new_dead_letter_topic.name update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, dead_letter_policy: dead_letter_policy @grpc = service.update_subscription update_grpc, :dead_letter_policy @resource_name = nil end |
#deadline ⇒ Integer
This value is the maximum number of seconds after a subscriber receives a message before the subscriber should acknowledge the message.
Makes an API call to retrieve the deadline value when called on a reference object. See #reference?.
116 117 118 119 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 116 def deadline ensure_grpc! @grpc.ack_deadline_seconds end |
#deadline=(new_deadline) ⇒ Object
Sets the maximum number of seconds after a subscriber receives a message before the subscriber should acknowledge the message.
128 129 130 131 132 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 128 def deadline= new_deadline update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, ack_deadline_seconds: new_deadline @grpc = service.update_subscription update_grpc, :ack_deadline_seconds @resource_name = nil end |
#delete ⇒ Boolean
Deletes an existing subscription. All pending messages in the subscription are immediately dropped.
688 689 690 691 692 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 688 def delete ensure_service! service.delete_subscription name true end |
#detach ⇒ Boolean
Detaches a subscription from its topic. All messages retained in the subscription are dropped. Detached
subscriptions don't receive messages from their topic and don't retain any backlog. Subsequent #pull and
#listen (pull and streaming pull) operations will raise FAILED_PRECONDITION. If the subscription is a push
subscription (see #push_config), pushes to the endpoint will stop. It may take a few minutes for the
subscription's detached state to be reflected in subsequent calls to #detached?.
714 715 716 717 718 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 714 def detach ensure_service! service.detach_subscription name true end |
#detached? ⇒ Boolean
Whether the subscription is detached from its topic. Detached subscriptions don't receive messages from their
topic and don't retain any backlog. #pull and #listen (pull and streaming pull) operations will raise
FAILED_PRECONDITION. If the subscription is a push subscription (see #push_config), pushes to the endpoint
will not be made. The default value is false.
See Topic#subscribe and #detach.
Makes an API call to retrieve the value when called on a reference object. See #reference?.
642 643 644 645 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 642 def detached? ensure_grpc! @grpc.detached end |
#endpoint ⇒ String
Returns the URL locating the endpoint to which messages should be
pushed. For example, a Webhook endpoint might use
https://example.com/push.
Makes an API call to retrieve the endpoint value when called on a reference object. See #reference?.
206 207 208 209 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 206 def endpoint ensure_grpc! @grpc.push_config&.push_endpoint end |
#endpoint=(new_endpoint) ⇒ Object
Sets the URL locating the endpoint to which messages should be pushed.
For example, a Webhook endpoint might use https://example.com/push.
217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 217 def endpoint= new_endpoint ensure_service! service.modify_push_config name, new_endpoint, {} return if reference? @grpc.push_config = Google::Cloud::PubSub::V1::PushConfig.new( push_endpoint: new_endpoint, attributes: {} ) end |
#exists? ⇒ Boolean
Determines whether the subscription exists in the Pub/Sub service.
Makes an API call to determine whether the subscription resource exists when called on a reference object. See #reference?.
663 664 665 666 667 668 669 670 671 672 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 663 def exists? # Always true if the object is not set as reference return true unless reference? # If we have a value, return it return @exists unless @exists.nil? ensure_grpc! @exists = true rescue Google::Cloud::NotFoundError @exists = false end |
#expires_in ⇒ Numeric?
The duration (in seconds) for when a subscription expires after the subscription goes inactive. A subscription is considered active as long as any connected subscriber is successfully consuming messages from the subscription or is issuing operations on the subscription.
If #expires_in= is not set, a default value of of 31 days will be used. The minimum allowed value is 1 day.
Makes an API call to retrieve the value when called on a reference object. See #reference?.
338 339 340 341 342 343 344 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 338 def expires_in ensure_grpc! return nil if @grpc.expiration_policy.nil? Convert.duration_to_number @grpc.expiration_policy.ttl end |
#expires_in=(ttl) ⇒ Object
Sets the duration (in seconds) for when a subscription expires after the subscription goes inactive.
See also #expires_in.
355 356 357 358 359 360 361 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 355 def expires_in= ttl new_expiration_policy = Google::Cloud::PubSub::V1::ExpirationPolicy.new ttl: Convert.number_to_duration(ttl) update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, expiration_policy: new_expiration_policy @grpc = service.update_subscription update_grpc, :expiration_policy @resource_name = nil end |
#filter ⇒ String
An expression written in the Cloud Pub/Sub filter language. If non-empty, then only Message instances whose
attributes field matches the filter are delivered on this subscription. If empty, then no messages are
filtered out.
370 371 372 373 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 370 def filter ensure_grpc! @grpc.filter.freeze end |
#labels ⇒ Hash
A hash of user-provided labels associated with this subscription. Labels can be used to organize and group subscriptions.See Creating and Managing Labels.
The returned hash is frozen and changes are not allowed. Use #labels= to update the labels for this subscription.
Makes an API call to retrieve the labels value when called on a reference object. See #reference?.
300 301 302 303 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 300 def labels ensure_grpc! @grpc.labels.to_h.freeze end |
#labels=(new_labels) ⇒ Object
Sets the hash of user-provided labels associated with this subscription. Labels can be used to organize and group subscriptions. Label keys and values can be no longer than 63 characters, can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. Label values are optional. Label keys must start with a letter and each label in the list must have a different key. See Creating and Managing Labels.
317 318 319 320 321 322 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 317 def labels= new_labels raise ArgumentError, "Value must be a Hash" if new_labels.nil? update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, labels: new_labels @grpc = service.update_subscription update_grpc, :labels @resource_name = nil end |
#listen(deadline: nil, message_ordering: nil, streams: nil, inventory: nil, threads: {}) {|received_message| ... } ⇒ Subscriber
At the time of this release, ordering keys are not yet publicly enabled and requires special project enablements.
Create a Google::Cloud::PubSub::Subscriber object that receives and processes messages using the code provided in the callback. Messages passed to the callback should acknowledge (ReceivedMessage#acknowledge!) or reject (ReceivedMessage#reject!) the message. If no action is taken, the message will be removed from the subscriber and made available for redelivery after the callback is completed.
Google Cloud Pub/Sub ordering keys provide the ability to ensure related messages are sent to subscribers in the order in which they were published. Messages can be tagged with an ordering key, a string that identifies related messages for which publish order should be respected. The service guarantees that, for a given ordering key and publisher, messages are sent to subscribers in the order in which they were published. Ordering does not require sacrificing high throughput or scalability, as the service automatically distributes messages for different ordering keys across subscribers.
To use ordering keys, the subscription must be created with message
ordering enabled (See Topic#subscribe and #message_ordering?)
before calling #listen. When enabled, the subscriber will deliver
messages with the same ordering_key in the order they were
published.
970 971 972 973 974 975 976 977 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 970 def listen deadline: nil, message_ordering: nil, streams: nil, inventory: nil, threads: {}, &block ensure_service! deadline ||= self.deadline = if .nil? Subscriber.new name, block, deadline: deadline, streams: streams, inventory: inventory, message_ordering: , threads: threads, service: service end |
#message_ordering? ⇒ Boolean
At the time of this release, ordering keys are not yet publicly enabled and requires special project enablements.
Whether message ordering has been enabled. When enabled, messages
published with the same ordering_key will be delivered in the order
they were published. When disabled, messages may be delivered in any
order.
See Topic#publish_async, #listen, and Message#ordering_key.
Makes an API call to retrieve the enable_message_ordering value when called on a reference object. See #reference?.
613 614 615 616 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 613 def ensure_grpc! @grpc. end |
#modify_ack_deadline(new_deadline, *messages) ⇒ Object
Modifies the acknowledge deadline for messages.
This indicates that more time is needed to process the messages, or to make the messages available for redelivery if the processing was interrupted.
See also ReceivedMessage#modify_ack_deadline!.
1036 1037 1038 1039 1040 1041 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1036 def modify_ack_deadline new_deadline, * ack_ids = coerce_ack_ids ensure_service! service.modify_ack_deadline name, ack_ids, new_deadline true end |
#name ⇒ String
The name of the subscription.
81 82 83 84 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 81 def name return @resource_name if reference? @grpc.name end |
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for this subscription.
1244 1245 1246 1247 1248 1249 1250 1251 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1244 def policy ensure_service! grpc = service.get_subscription_policy name policy = Policy.from_grpc grpc return policy unless block_given? yield policy update_policy policy end |
#pull(immediate: true, max: 100) ⇒ Array<Google::Cloud::PubSub::ReceivedMessage>
Pulls messages from the server. Returns an empty list if there are no
messages available in the backlog. Raises an ApiError with status
UNAVAILABLE if there are too many concurrent pull requests pending
for the given subscription.
See also #listen for the preferred way to process messages as they become available.
772 773 774 775 776 777 778 779 780 781 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 772 def pull immediate: true, max: 100 ensure_service! = { immediate: immediate, max: max } list_grpc = service.pull name, Array(list_grpc.).map do |msg_grpc| ReceivedMessage.from_grpc msg_grpc, self end rescue Google::Cloud::DeadlineExceededError [] end |
#push_config {|push_config| ... } ⇒ Subscription::PushConfig
Inspect the Subscription's push configuration settings. The configuration can be changed by modifying the values in the method's block.
Subscription objects that are reference only will return an empty PushConfig object, which can be configured and saved using the method's block. Unlike #endpoint, which will retrieve the full resource from the API before returning. To get the actual values for a reference object, call #reload! before calling #push_config.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 267 def push_config ensure_service! orig_config = reference? ? nil : @grpc.push_config config = PushConfig.from_grpc orig_config if block_given? old_config = config.to_grpc.dup yield config new_config = config.to_grpc if old_config != new_config # has the object been changed? update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, push_config: new_config @grpc = service.update_subscription update_grpc, :push_config end end config.freeze end |
#reference? ⇒ Boolean
Determines whether the subscription object was created without retrieving the resource representation from the Pub/Sub service.
1165 1166 1167 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1165 def reference? @grpc.nil? end |
#reload! ⇒ Google::Cloud::PubSub::Subscription Also known as: refresh!
Reloads the subscription with current data from the Pub/Sub service.
1202 1203 1204 1205 1206 1207 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1202 def reload! ensure_service! @grpc = service.get_subscription name @resource_name = nil self end |
#remove_dead_letter_policy ⇒ Boolean
Removes an existing dead letter policy. A dead letter policy specifies the conditions for dead lettering messages in the subscription. If a dead letter policy is not set, dead lettering is disabled.
See #dead_letter_topic, #dead_letter_topic=, #dead_letter_max_delivery_attempts and #dead_letter_max_delivery_attempts=.
536 537 538 539 540 541 542 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 536 def remove_dead_letter_policy ensure_grpc! return false if @grpc.dead_letter_policy.nil? update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, dead_letter_policy: nil @grpc = service.update_subscription update_grpc, :dead_letter_policy true end |
#resource? ⇒ Boolean
Determines whether the subscription object was created with a resource representation from the Pub/Sub service.
1184 1185 1186 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1184 def resource? !@grpc.nil? end |
#retain_acked ⇒ Boolean
Indicates whether to retain acknowledged messages. If true, then
messages are not expunged from the subscription's backlog, even if
they are acknowledged, until they fall out of the #retention window.
Default is false.
Makes an API call to retrieve the retain_acked value when called on a reference object. See #reference?.
146 147 148 149 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 146 def retain_acked ensure_grpc! @grpc. end |
#retain_acked=(new_retain_acked) ⇒ Object
Sets whether to retain acknowledged messages.
157 158 159 160 161 162 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 157 def retain_acked= new_retain_acked update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, retain_acked_messages: !(!new_retain_acked) @grpc = service.update_subscription update_grpc, :retain_acked_messages @resource_name = nil end |
#retention ⇒ Numeric
How long to retain unacknowledged messages in the subscription's
backlog, from the moment a message is published. If
#retain_acked is true, then this also configures the retention of
acknowledged messages, and thus configures how far back in time a
#seek can be done. Cannot be more than 604,800 seconds (7 days) or
less than 600 seconds (10 minutes). Default is 604,800 seconds (7
days).
Makes an API call to retrieve the retention value when called on a reference object. See #reference?.
178 179 180 181 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 178 def retention ensure_grpc! Convert.duration_to_number @grpc. end |
#retention=(new_retention) ⇒ Object
Sets the message retention duration in seconds.
188 189 190 191 192 193 194 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 188 def retention= new_retention new_retention_duration = Convert.number_to_duration new_retention update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, message_retention_duration: new_retention_duration @grpc = service.update_subscription update_grpc, :message_retention_duration @resource_name = nil end |
#retry_policy ⇒ RetryPolicy?
A policy that specifies how Cloud Pub/Sub retries message delivery for this subscription. If nil, the
default retry policy is applied. This generally implies that messages will be retried as soon as possible
for healthy subscribers. Retry Policy will be triggered on NACKs or acknowledgement deadline exceeded events
for a given message.
564 565 566 567 568 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 564 def retry_policy ensure_grpc! return nil unless @grpc.retry_policy RetryPolicy.from_grpc @grpc.retry_policy end |
#retry_policy=(new_retry_policy) ⇒ Object
Sets a policy that specifies how Cloud Pub/Sub retries message delivery for this subscription. If nil, the
default retry policy is applied. This generally implies that messages will be retried as soon as possible
for healthy subscribers. Retry Policy will be triggered on NACKs or acknowledgement deadline exceeded events
for a given message.
590 591 592 593 594 595 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 590 def retry_policy= new_retry_policy ensure_grpc! new_retry_policy = new_retry_policy.to_grpc if new_retry_policy update_grpc = Google::Cloud::PubSub::V1::Subscription.new name: name, retry_policy: new_retry_policy @grpc = service.update_subscription update_grpc, :retry_policy end |
#seek(snapshot) ⇒ Boolean
Resets the subscription's backlog to a given Google::Cloud::PubSub::Snapshot or to a point in time, whichever is provided in the request.
1144 1145 1146 1147 1148 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1144 def seek snapshot ensure_service! service.seek name, snapshot true end |
#test_permissions(*permissions) ⇒ Array<String>
Tests the specified permissions against the Cloud IAM access control policy.
1321 1322 1323 1324 1325 1326 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1321 def * = Array().flatten ensure_service! grpc = service. name, grpc. end |
#topic ⇒ Topic
The Topic from which this subscription receives messages.
Makes an API call to retrieve the topic information when called on a reference object. See #reference?.
102 103 104 105 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 102 def topic ensure_grpc! Topic.from_name @grpc.topic, service end |
#update_policy(new_policy) ⇒ Policy Also known as: policy=
Updates the Cloud IAM access control
policy for this subscription. 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.
1282 1283 1284 1285 1286 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 1282 def update_policy new_policy ensure_service! grpc = service.set_subscription_policy name, new_policy.to_grpc Policy.from_grpc grpc end |
#wait_for_messages(max: 100) ⇒ Array<Google::Cloud::PubSub::ReceivedMessage>
Pulls from the server while waiting for messages to become available. This is the same as:
subscription.pull immediate: false
See also #listen for the preferred way to process messages as they become available.
809 810 811 |
# File 'lib/google/cloud/pubsub/subscription.rb', line 809 def max: 100 pull immediate: false, max: max end |