PHP Class Google\Cloud\PubSub\V1\SubscriberClient

EXPERIMENTAL: this client library class has not yet been declared beta. This class may change more frequently than those which have been declared beta or 1.0, including changes which break backwards compatibility. This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started: try { $subscriberClient = new SubscriberClient(); $formattedName = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $formattedTopic = SubscriberClient::formatTopicName("[PROJECT]", "[TOPIC]"); $response = $subscriberClient->createSubscription($formattedName, $formattedTopic); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } } Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php

Public Methods

Method Description
__construct ( array $options = [] ) Constructor.
acknowledge ( string $subscription, string[] $ackIds, array $optionalArgs = [] ) Acknowledges the messages associated with the ack_ids in the AcknowledgeRequest. The Pub/Sub system can remove the relevant messages from the subscription.
close ( ) Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.
createSubscription ( string $name, string $topic, array $optionalArgs = [] ) : google\pubsub\v1\Subscription Creates a subscription to a given topic.
deleteSubscription ( string $subscription, array $optionalArgs = [] ) 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.
formatProjectName ( $project ) Formats a string containing the fully-qualified path to represent a project resource.
formatSubscriptionName ( $project, $subscription ) Formats a string containing the fully-qualified path to represent a subscription resource.
formatTopicName ( $project, $topic ) Formats a string containing the fully-qualified path to represent a topic resource.
getIamPolicy ( string $resource, array $optionalArgs = [] ) : google\iam\v1\Policy Gets the access control policy for a resource.
getSubscription ( string $subscription, array $optionalArgs = [] ) : google\pubsub\v1\Subscription Gets the configuration details of a subscription.
listSubscriptions ( string $project, array $optionalArgs = [] ) : Google\GAX\PagedListResponse Lists matching subscriptions.
modifyAckDeadline ( string $subscription, string[] $ackIds, integer $ackDeadlineSeconds, array $optionalArgs = [] ) 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.
modifyPushConfig ( string $subscription, google\pubsub\v1\PushConfig $pushConfig, array $optionalArgs = [] ) Modifies the PushConfig for a specified subscription.
parseProjectFromProjectName ( $projectName ) Parses the project from the given fully-qualified path which represents a project resource.
parseProjectFromSubscriptionName ( $subscriptionName ) Parses the project from the given fully-qualified path which represents a subscription resource.
parseProjectFromTopicName ( $topicName ) Parses the project from the given fully-qualified path which represents a topic resource.
parseSubscriptionFromSubscriptionName ( $subscriptionName ) Parses the subscription from the given fully-qualified path which represents a subscription resource.
parseTopicFromTopicName ( $topicName ) Parses the topic from the given fully-qualified path which represents a topic resource.
pull ( string $subscription, integer $maxMessages, array $optionalArgs = [] ) : google\pubsub\v1\PullResponse Pulls messages from the server. Returns an empty list if there are no messages available in the backlog. The server may return UNAVAILABLE if there are too many concurrent pull requests pending for the given subscription.
setIamPolicy ( string $resource, google\iam\v1\Policy $policy, array $optionalArgs = [] ) : google\iam\v1\Policy Sets the access control policy on the specified resource. Replaces any existing policy.
testIamPermissions ( string $resource, string[] $permissions, array $optionalArgs = [] ) : google\iam\v1\TestIamPermissionsResponse Returns permissions that a caller has on the specified resource.

Private Methods

Method Description
createCredentialsCallback ( )
getPageStreamingDescriptors ( )
getProjectNameTemplate ( )
getSubscriptionNameTemplate ( )
getTopicNameTemplate ( )

Method Details

__construct() public method

Constructor.
public __construct ( array $options = [] )
$options array { Optional. Options for configuring the service API wrapper. @type string $serviceAddress The domain name of the API remote host. Default 'pubsub.googleapis.com'. @type mixed $port The port on which to connect to the remote host. Default 443. @type Grpc\ChannelCredentials $sslCreds A `ChannelCredentials` for use with an SSL-enabled channel. Default: a credentials object returned from Grpc\ChannelCredentials::createSsl() @type array $scopes A string array of scopes to use when acquiring credentials. Default the scopes for the Google Cloud Pub/Sub API. @type array $retryingOverride An associative array of string => RetryOptions, where the keys are method names (e.g. 'createFoo'), that overrides default retrying settings. A value of null indicates that the method in question should not retry. @type int $timeoutMillis The timeout in milliseconds to use for calls that don't use retries. For calls that use retries, set the timeout in RetryOptions. Default: 30000 (30 seconds) @type string $appName The codename of the calling service. Default 'gax'. @type string $appVersion The version of the calling service. Default: the current version of GAX. @type Google\Auth\CredentialsLoader $credentialsLoader A CredentialsLoader object created using the Google\Auth library. }

acknowledge() public method

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. Sample code: try { $subscriberClient = new SubscriberClient(); $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $ackIds = []; $subscriberClient->acknowledge($formattedSubscription, $ackIds); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public acknowledge ( string $subscription, string[] $ackIds, array $optionalArgs = [] )
$subscription string The subscription whose message is being acknowledged. Format is `projects/{project}/subscriptions/{sub}`.
$ackIds string[] The acknowledgment ID for the messages being acknowledged that was returned by the Pub/Sub system in the `Pull` response. Must not be empty.
$optionalArgs array { Optional. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }

close() public method

Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.
public close ( )

createSubscription() public method

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. Sample code: try { $subscriberClient = new SubscriberClient(); $formattedName = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $formattedTopic = SubscriberClient::formatTopicName("[PROJECT]", "[TOPIC]"); $response = $subscriberClient->createSubscription($formattedName, $formattedTopic); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public createSubscription ( string $name, string $topic, array $optionalArgs = [] ) : google\pubsub\v1\Subscription
$name string The name of the subscription. It must have the format `"projects/{project}/subscriptions/{subscription}"`. `{subscription}` must start with a letter, and contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters in length, and it must not start with `"goog"`.
$topic string The name of the topic from which this subscription is receiving messages. Format is `projects/{project}/topics/{topic}`. The value of this field will be `_deleted-topic_` if the topic has been deleted.
$optionalArgs array { Optional. @type PushConfig $pushConfig If push delivery is used with this subscription, this field is used to configure it. An empty `pushConfig` signifies that the subscriber will pull and ack messages using API methods. @type int $ackDeadlineSeconds This value is the maximum time after a subscriber receives a message before the subscriber should acknowledge the message. After message delivery but before the ack deadline expires and before the message is acknowledged, it is an outstanding message and will not be delivered again during that time (on a best-effort basis). For pull subscriptions, this value is used as the initial value for the ack deadline. To override this value for a given message, call `ModifyAckDeadline` with the corresponding `ack_id` if using pull. The minimum custom deadline you can specify is 10 seconds. The maximum custom deadline you can specify is 600 seconds (10 minutes). If this parameter is 0, a default value of 10 seconds is used. For push delivery, this value is also used to set the request timeout for the call to the push endpoint. If the subscriber never acknowledges the message, the Pub/Sub system will eventually redeliver the message. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }
return google\pubsub\v1\Subscription

deleteSubscription() public method

Sample code: try { $subscriberClient = new SubscriberClient(); $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $subscriberClient->deleteSubscription($formattedSubscription); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public deleteSubscription ( string $subscription, array $optionalArgs = [] )
$subscription string The subscription to delete. Format is `projects/{project}/subscriptions/{sub}`.
$optionalArgs array { Optional. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }

formatProjectName() public static method

Formats a string containing the fully-qualified path to represent a project resource.
public static formatProjectName ( $project )

formatSubscriptionName() public static method

Formats a string containing the fully-qualified path to represent a subscription resource.
public static formatSubscriptionName ( $project, $subscription )

formatTopicName() public static method

Formats a string containing the fully-qualified path to represent a topic resource.
public static formatTopicName ( $project, $topic )

getIamPolicy() public method

Returns an empty policy if the resource exists and does not have a policy set. Sample code: try { $subscriberClient = new SubscriberClient(); $formattedResource = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $response = $subscriberClient->getIamPolicy($formattedResource); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public getIamPolicy ( string $resource, array $optionalArgs = [] ) : google\iam\v1\Policy
$resource string REQUIRED: The resource for which the policy is being requested. `resource` is usually specified as a path. For example, a Project resource is specified as `projects/{project}`.
$optionalArgs array { Optional. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }
return google\iam\v1\Policy

getSubscription() public method

Sample code: try { $subscriberClient = new SubscriberClient(); $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $response = $subscriberClient->getSubscription($formattedSubscription); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public getSubscription ( string $subscription, array $optionalArgs = [] ) : google\pubsub\v1\Subscription
$subscription string The name of the subscription to get. Format is `projects/{project}/subscriptions/{sub}`.
$optionalArgs array { Optional. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }
return google\pubsub\v1\Subscription

listSubscriptions() public method

Sample code: try { $subscriberClient = new SubscriberClient(); $formattedProject = SubscriberClient::formatProjectName("[PROJECT]"); foreach ($subscriberClient->listSubscriptions($formattedProject) as $element) { doThingsWith(element); } } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public listSubscriptions ( string $project, array $optionalArgs = [] ) : Google\GAX\PagedListResponse
$project string The name of the cloud project that subscriptions belong to. Format is `projects/{project}`.
$optionalArgs array { Optional. @type int $pageSize The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. @type string $pageToken A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }
return Google\GAX\PagedListResponse

modifyAckDeadline() public method

Sample code: try { $subscriberClient = new SubscriberClient(); $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $ackIds = []; $ackDeadlineSeconds = 0; $subscriberClient->modifyAckDeadline($formattedSubscription, $ackIds, $ackDeadlineSeconds); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public modifyAckDeadline ( string $subscription, string[] $ackIds, integer $ackDeadlineSeconds, array $optionalArgs = [] )
$subscription string The name of the subscription. Format is `projects/{project}/subscriptions/{sub}`.
$ackIds string[] List of acknowledgment IDs.
$ackDeadlineSeconds integer The new ack deadline with respect to the time this request was sent to the Pub/Sub system. For example, if the value is 10, the new ack deadline will expire 10 seconds after the `ModifyAckDeadline` call was made. Specifying zero may immediately make the message available for another pull request. The minimum deadline you can specify is 0 seconds. The maximum deadline you can specify is 600 seconds (10 minutes).
$optionalArgs array { Optional. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }

modifyPushConfig() public method

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. Sample code: try { $subscriberClient = new SubscriberClient(); $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $pushConfig = new PushConfig(); $subscriberClient->modifyPushConfig($formattedSubscription, $pushConfig); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public modifyPushConfig ( string $subscription, google\pubsub\v1\PushConfig $pushConfig, array $optionalArgs = [] )
$subscription string The name of the subscription. Format is `projects/{project}/subscriptions/{sub}`.
$pushConfig google\pubsub\v1\PushConfig The push configuration for future deliveries. An empty `pushConfig` indicates that the Pub/Sub system should stop pushing messages from the given subscription and allow messages to be pulled and acknowledged - effectively pausing the subscription if `Pull` is not called.
$optionalArgs array { Optional. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }

parseProjectFromProjectName() public static method

Parses the project from the given fully-qualified path which represents a project resource.
public static parseProjectFromProjectName ( $projectName )

parseProjectFromSubscriptionName() public static method

Parses the project from the given fully-qualified path which represents a subscription resource.
public static parseProjectFromSubscriptionName ( $subscriptionName )

parseProjectFromTopicName() public static method

Parses the project from the given fully-qualified path which represents a topic resource.
public static parseProjectFromTopicName ( $topicName )

parseSubscriptionFromSubscriptionName() public static method

Parses the subscription from the given fully-qualified path which represents a subscription resource.
public static parseSubscriptionFromSubscriptionName ( $subscriptionName )

parseTopicFromTopicName() public static method

Parses the topic from the given fully-qualified path which represents a topic resource.
public static parseTopicFromTopicName ( $topicName )

pull() public method

Sample code: try { $subscriberClient = new SubscriberClient(); $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $maxMessages = 0; $response = $subscriberClient->pull($formattedSubscription, $maxMessages); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public pull ( string $subscription, integer $maxMessages, array $optionalArgs = [] ) : google\pubsub\v1\PullResponse
$subscription string The subscription from which messages should be pulled. Format is `projects/{project}/subscriptions/{sub}`.
$maxMessages integer The maximum number of messages returned for this request. The Pub/Sub system may return fewer than the number specified.
$optionalArgs array { Optional. @type bool $returnImmediately If this field set to true, the system will respond immediately even if it there are no messages available to return in the `Pull` response. Otherwise, the system may wait (for a bounded amount of time) until at least one message is available, rather than returning no messages. The client may cancel the request if it does not wish to wait any longer for the response. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }
return google\pubsub\v1\PullResponse

setIamPolicy() public method

Sample code: try { $subscriberClient = new SubscriberClient(); $formattedResource = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $policy = new Policy(); $response = $subscriberClient->setIamPolicy($formattedResource, $policy); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public setIamPolicy ( string $resource, google\iam\v1\Policy $policy, array $optionalArgs = [] ) : google\iam\v1\Policy
$resource string REQUIRED: The resource for which the policy is being specified. `resource` is usually specified as a path. For example, a Project resource is specified as `projects/{project}`.
$policy google\iam\v1\Policy REQUIRED: The complete policy to be applied to the `resource`. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.
$optionalArgs array { Optional. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }
return google\iam\v1\Policy

testIamPermissions() public method

If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error. Sample code: try { $subscriberClient = new SubscriberClient(); $formattedResource = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $permissions = []; $response = $subscriberClient->testIamPermissions($formattedResource, $permissions); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public testIamPermissions ( string $resource, string[] $permissions, array $optionalArgs = [] ) : google\iam\v1\TestIamPermissionsResponse
$resource string REQUIRED: The resource for which the policy detail is being requested. `resource` is usually specified as a path. For example, a Project resource is specified as `projects/{project}`.
$permissions string[] The set of permissions to check for the `resource`. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
$optionalArgs array { Optional. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }
return google\iam\v1\TestIamPermissionsResponse