Cloud PubSub V1 Client - Class SubscriberClient (1.45.2)

Reference documentation and code samples for the Cloud PubSub V1 Client class SubscriberClient.

Service Description: The service that an application uses to manipulate subscriptions and to consume messages from a subscription via the Pull method or by establishing a bi-directional stream using the StreamingPull method.

This class is currently experimental and may be subject to changes.

Namespace

Google \ Cloud \ PubSub \ V1 \ Client

Methods

__construct

Constructor.

Parameters
NameDescription
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

acknowledge

Acknowledges the messages associated with the ack_ids in the AcknowledgeRequest. The Pub/Sub system can remove the relevant messages from the subscription.

Acknowledging a message whose ack deadline has expired may succeed, but such a message may be redelivered later. Acknowledging a message more than once will not result in an error.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::acknowledgeAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\AcknowledgeRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

createSnapshot

Creates a snapshot from the requested subscription. Snapshots are used in Seek 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.

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. The generated name is populated in the returned Snapshot object. Note that for REST API requests, you must specify a name in the request.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::createSnapshotAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\CreateSnapshotRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\PubSub\V1\Snapshot

createSubscription

Creates a subscription to a given topic. See the resource name rules.

If the subscription already exists, returns ALREADY_EXISTS. If the corresponding topic doesn't exist, returns NOT_FOUND.

If the name is not provided in the request, the server will assign a random name for this subscription on the same project as the topic, conforming to the resource name format. The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::createSubscriptionAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\Subscription

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\PubSub\V1\Subscription

deleteSnapshot

Removes an existing snapshot. Snapshots are used in Seek 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.

When the snapshot is deleted, 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.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::deleteSnapshotAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\DeleteSnapshotRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

deleteSubscription

Deletes an existing subscription. All messages retained in the subscription are immediately dropped. Calls to Pull after deletion will return NOT_FOUND. After a subscription is deleted, a new one may be created with the same name, but the new one has no association with the old subscription or its topic unless the same topic is specified.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::deleteSubscriptionAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\DeleteSubscriptionRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

getSnapshot

Gets the configuration details of a snapshot. Snapshots are used in Seek 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.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::getSnapshotAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\GetSnapshotRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\PubSub\V1\Snapshot

getSubscription

Gets the configuration details of a subscription.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::getSubscriptionAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\GetSubscriptionRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\PubSub\V1\Subscription

listSnapshots

Lists the existing snapshots. Snapshots are used in Seek 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.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::listSnapshotsAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\ListSnapshotsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse

listSubscriptions

Lists matching subscriptions.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::listSubscriptionsAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\ListSubscriptionsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse

modifyAckDeadline

Modifies the ack deadline for a specific message. This method is useful to indicate that more time is needed to process a message by the subscriber, or to make the message available for redelivery if the processing was interrupted. Note that this does not modify the subscription-level ackDeadlineSeconds used for subsequent messages.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::modifyAckDeadlineAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\ModifyAckDeadlineRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

modifyPushConfig

Modifies the PushConfig for a specified subscription.

This may be used to change a push subscription to a pull one (signified by an empty PushConfig) or vice versa, or change the endpoint URL and other attributes of a push subscription. Messages will accumulate for delivery continuously through the call regardless of changes to the PushConfig.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::modifyPushConfigAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\ModifyPushConfigRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

pull

Pulls messages from the server.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::pullAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\PullRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\PubSub\V1\PullResponse

seek

Seeks an existing subscription to a point in time or to a given snapshot, whichever is provided in the request. Snapshots are used in Seek 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. Note that both the subscription and the snapshot must be on the same topic.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::seekAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\SeekRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\PubSub\V1\SeekResponse

streamingPull

Establishes a stream with the server, which sends messages down to the client. The client streams acknowledgements and ack deadline modifications back to the server. The server will close the stream and return the status on any error. The server may close the stream with status UNAVAILABLE to reassign server-side resources, in which case, the client should re-establish the stream. Flow control can be achieved by configuring the underlying RPC channel.

Parameters
NameDescription
callOptions array

Optional.

↳ timeoutMillis int

Timeout to use for this call.

Returns
TypeDescription
Google\ApiCore\BidiStream

updateSnapshot

Updates an existing snapshot. Snapshots are used in Seek 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.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::updateSnapshotAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\UpdateSnapshotRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\PubSub\V1\Snapshot

updateSubscription

Updates an existing subscription. Note that certain properties of a subscription, such as its topic, are not modifiable.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::updateSubscriptionAsync() .

Parameters
NameDescription
request Google\Cloud\PubSub\V1\UpdateSubscriptionRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\PubSub\V1\Subscription

getIamPolicy

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::getIamPolicyAsync() .

Parameters
NameDescription
request Google\Cloud\Iam\V1\GetIamPolicyRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\Policy

setIamPolicy

Sets the access control policy on the specified resource. Replaces any existing policy.

Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::setIamPolicyAsync() .

Parameters
NameDescription
request Google\Cloud\Iam\V1\SetIamPolicyRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\Policy

testIamPermissions

Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

The async variant is Google\Cloud\PubSub\V1\Client\BaseClient\self::testIamPermissionsAsync() .

Parameters
NameDescription
request Google\Cloud\Iam\V1\TestIamPermissionsRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Iam\V1\TestIamPermissionsResponse

acknowledgeAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\AcknowledgeRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

createSnapshotAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\CreateSnapshotRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

createSubscriptionAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\Subscription
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

deleteSnapshotAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\DeleteSnapshotRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

deleteSubscriptionAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\DeleteSubscriptionRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

getSnapshotAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\GetSnapshotRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

getSubscriptionAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\GetSubscriptionRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

listSnapshotsAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\ListSnapshotsRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

listSubscriptionsAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\ListSubscriptionsRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

modifyAckDeadlineAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\ModifyAckDeadlineRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

modifyPushConfigAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\ModifyPushConfigRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

pullAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\PullRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

seekAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\SeekRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

updateSnapshotAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\UpdateSnapshotRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

updateSubscriptionAsync

Parameters
NameDescription
request Google\Cloud\PubSub\V1\UpdateSubscriptionRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

getIamPolicyAsync

Parameters
NameDescription
request Google\Cloud\Iam\V1\GetIamPolicyRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

setIamPolicyAsync

Parameters
NameDescription
request Google\Cloud\Iam\V1\SetIamPolicyRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

testIamPermissionsAsync

Parameters
NameDescription
request Google\Cloud\Iam\V1\TestIamPermissionsRequest
optionalArgs = [] array
Returns
TypeDescription
GuzzleHttp\Promise\PromiseInterface

static::deletedTopicName

Formats a string containing the fully-qualified path to represent a deleted-topic resource.

Returns
TypeDescription
stringThe formatted _deleted-topic_ resource.

static::projectName

Formats a string containing the fully-qualified path to represent a project resource.

Parameter
NameDescription
project string
Returns
TypeDescription
stringThe formatted project resource.

static::projectTopicName

Formats a string containing the fully-qualified path to represent a project_topic resource.

Parameters
NameDescription
project string
topic string
Returns
TypeDescription
stringThe formatted project_topic resource.

static::snapshotName

Formats a string containing the fully-qualified path to represent a snapshot resource.

Parameters
NameDescription
project string
snapshot string
Returns
TypeDescription
stringThe formatted snapshot resource.

static::subscriptionName

Formats a string containing the fully-qualified path to represent a subscription resource.

Parameters
NameDescription
project string
subscription string
Returns
TypeDescription
stringThe formatted subscription resource.

static::topicName

Formats a string containing the fully-qualified path to represent a topic resource.

Parameters
NameDescription
project string
topic string
Returns
TypeDescription
stringThe formatted topic resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • deletedTopic: deleted-topic
  • project: projects/{project}
  • projectTopic: projects/{project}/topics/{topic}
  • snapshot: projects/{project}/snapshots/{snapshot}
  • subscription: projects/{project}/subscriptions/{subscription}
  • topic: projects/{project}/topics/{topic}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.