Creates a snapshot from the requested subscription. Snapshots are used in <a
href="https://cloud.google.com/pubsub/docs/replay-overview">Seek</a> operations, which
allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment
state of messages in an existing subscription to the state captured by a snapshot.
<br><br> <b>BETA:</b> This feature is part of a beta release. This API
might be changed in backward-incompatible ways and is not recommended for production use. It is
not subject to any SLA or deprecation policy.<br><br> If the snapshot already
exists, returns `ALREADY_EXISTS`. If the requested subscription doesn't exist, returns
`NOT_FOUND`. If the backlog in the subscription is too old -- and the resulting snapshot would
expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned. See also the
`Snapshot.expire_time` field. If the name is not provided in the request, the server will
assign a random name for this snapshot on the same project as the subscription, conforming to
the [resource name format](https://cloud.google.com/pubsub/docs/admin#resource_names). The
generated name is populated in the returned Snapshot object. Note that for REST API requests,
you must specify a name in the request.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSnapshotName name = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
CreateSnapshotRequest request = CreateSnapshotRequest.newBuilder()
.setName(name.toString())
.setSubscription(subscription.toString())
.build();
Snapshot response = subscriptionAdminClient.createSnapshot(request);
}