Cloud Pub/Sub API - Class Google::Cloud::PubSub::Snapshot (v2.9.2)

Reference documentation and code samples for the Cloud Pub/Sub API class Google::Cloud::PubSub::Snapshot.

Snapshot

A named resource created from a subscription to retain a stream of messages from a topic. A 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_snapshot operation; as well as:
  • Any messages published to the subscription's topic following the successful completion of the create_snapshot operation.

Inherits

  • Object

Example

require "google/cloud/pubsub"

pubsub = Google::Cloud::PubSub.new
sub = pubsub.subscription "my-sub"

snapshot = sub.create_snapshot "my-snapshot"
snapshot.name #=> "projects/my-project/snapshots/my-snapshot"

Methods

#delete

def delete() -> Boolean

Removes an existing snapshot. All messages retained in the snapshot are immediately dropped. After a snapshot is deleted, a new one may be created with the same name, but the new one has no association with the old snapshot or its subscription, unless the same subscription is specified.

Returns
  • (Boolean) — Returns true if the snapshot was deleted.
Example
require "google/cloud/pubsub"

pubsub = Google::Cloud::PubSub.new

pubsub.snapshots.each do |snapshot|
  snapshot.delete
end

#expiration_time

def expiration_time() -> Time

The snapshot is guaranteed to exist up until this time. A newly-created snapshot expires no later than 7 days from the time of its creation. Its exact lifetime is determined at creation by the existing backlog in the source subscription. Specifically, the lifetime of the snapshot is 7 days - (age of oldest unacked message in the subscription). For example, consider a subscription whose oldest unacked message is 3 days old. If a snapshot is created from this subscription, the snapshot -- which will always capture this 3-day-old backlog as long as the snapshot exists -- will expire in 4 days.

Returns
  • (Time) — The time until which the snapshot is guaranteed to exist.
Example
require "google/cloud/pubsub"

pubsub = Google::Cloud::PubSub.new
sub = pubsub.subscription "my-sub"

snapshot = sub.create_snapshot "my-snapshot"
snapshot.topic.name #=> "projects/my-project/topics/my-topic"
snapshot.expiration_time

#labels

def labels() -> Hash

A hash of user-provided labels associated with this snapshot. Labels can be used to organize and group snapshots.See Creating and Managing Labels.

The returned hash is frozen and changes are not allowed. Use #labels= to update the labels for this snapshot.

Returns
  • (Hash) — The frozen labels hash.

#labels=

def labels=(new_labels)

Sets the hash of user-provided labels associated with this snapshot. Labels can be used to organize and group snapshots. 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.

Parameter
  • new_labels (Hash) — The new labels hash.
Raises
  • (ArgumentError)

#name

def name() -> String

The name of the snapshot.

Returns
  • (String) — A fully-qualified snapshot name in the form projects/{project_id}/snapshots/{snapshot_id}.

#topic

def topic() -> Topic

The Topic from which this snapshot is retaining messages.

Returns
Example
require "google/cloud/pubsub"

pubsub = Google::Cloud::PubSub.new
sub = pubsub.subscription "my-sub"

snapshot = sub.create_snapshot "my-snapshot"
snapshot.topic.name #=> "projects/my-project/topics/my-topic"