class SubscriberClient

Service Description: The service that an application uses to manipulate subscriptions and to consume messages from a subscription via the Pull method.

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.

Constants

SERVICE_ADDRESS

The default address of the service.

DEFAULT_SERVICE_PORT

The default port of the service.

DEFAULT_TIMEOUT_MILLIS

The default timeout for non-retrying methods.

_GAX_VERSION

_CODEGEN_NAME

_CODEGEN_VERSION

Methods

static 
formatProjectName($project)

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

static 
formatSubscriptionName($project, $subscription)

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

static 
formatTopicName($project, $topic)

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

static 
parseProjectFromProjectName($projectName)

Parses the project from the given fully-qualified path which represents a project resource.

static 
parseProjectFromSubscriptionName($subscriptionName)

Parses the project from the given fully-qualified path which represents a subscription resource.

static 
parseSubscriptionFromSubscriptionName($subscriptionName)

Parses the subscription from the given fully-qualified path which represents a subscription resource.

static 
parseProjectFromTopicName($topicName)

Parses the project from the given fully-qualified path which represents a topic resource.

static 
parseTopicFromTopicName($topicName)

Parses the topic from the given fully-qualified path which represents a topic resource.

__construct(array $options = array())

Constructor.

createSubscription(string $name, string $topic, array $optionalArgs = array())

Creates a subscription to a given topic.

getSubscription(string $subscription, array $optionalArgs = array())

Gets the configuration details of a subscription.

listSubscriptions(string $project, array $optionalArgs = array())

Lists matching subscriptions.

deleteSubscription(string $subscription, array $optionalArgs = array())

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.

modifyAckDeadline(string $subscription, string[] $ackIds, int $ackDeadlineSeconds, array $optionalArgs = array())

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.

acknowledge(string $subscription, string[] $ackIds, array $optionalArgs = array())

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

pull(string $subscription, int $maxMessages, array $optionalArgs = array())

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.

modifyPushConfig(string $subscription, PushConfig $pushConfig, array $optionalArgs = array())

Modifies the PushConfig for a specified subscription.

setIamPolicy(string $resource, Policy $policy, array $optionalArgs = array())

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

getIamPolicy(string $resource, array $optionalArgs = array())

Gets the access control policy for a resource.

testIamPermissions(string $resource, string[] $permissions, array $optionalArgs = array())

Returns permissions that a caller has on the specified resource.

close()

Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.

Details

at line line 109
static formatProjectName($project)

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

Parameters

$project

at line line 120
static formatSubscriptionName($project, $subscription)

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

Parameters

$project
$subscription

at line line 132
static formatTopicName($project, $topic)

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

Parameters

$project
$topic

at line line 144
static parseProjectFromProjectName($projectName)

Parses the project from the given fully-qualified path which represents a project resource.

Parameters

$projectName

at line line 153
static parseProjectFromSubscriptionName($subscriptionName)

Parses the project from the given fully-qualified path which represents a subscription resource.

Parameters

$subscriptionName

at line line 162
static parseSubscriptionFromSubscriptionName($subscriptionName)

Parses the subscription from the given fully-qualified path which represents a subscription resource.

Parameters

$subscriptionName

at line line 171
static parseProjectFromTopicName($topicName)

Parses the project from the given fully-qualified path which represents a topic resource.

Parameters

$topicName

at line line 180
static parseTopicFromTopicName($topicName)

Parses the topic from the given fully-qualified path which represents a topic resource.

Parameters

$topicName

at line line 262
__construct(array $options = array())

Constructor.

Parameters

array $options { 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.

}

at line line 422
Subscription createSubscription(string $name, string $topic, array $optionalArgs = array())

Creates a subscription to a given topic.

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();
    }
}

Parameters

string $name 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".
string $topic 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.
array $optionalArgs { 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 Value

Subscription

Exceptions

ApiException if the remote call fails

at line line 483
Subscription getSubscription(string $subscription, array $optionalArgs = array())

Gets the configuration details of a subscription.

Sample code:


try {
    $subscriberClient = new SubscriberClient();
    $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
    $response = $subscriberClient->getSubscription($formattedSubscription);
} finally {
    if (isset($subscriberClient)) {
        $subscriberClient->close();
    }
}

Parameters

string $subscription The name of the subscription to get. Format is projects/{project}/subscriptions/{sub}.
array $optionalArgs { 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 Value

Subscription

Exceptions

ApiException if the remote call fails

at line line 548
PagedListResponse listSubscriptions(string $project, array $optionalArgs = array())

Lists matching subscriptions.

Sample code:


try {
    $subscriberClient = new SubscriberClient();
    $formattedProject = SubscriberClient::formatProjectName("[PROJECT]");
    foreach ($subscriberClient->listSubscriptions($formattedProject)->iterateAllElements() as $element) {
        // doThingsWith(element);
    }
} finally {
    if (isset($subscriberClient)) {
        $subscriberClient->close();
    }
}

Parameters

string $project The name of the cloud project that subscriptions belong to. Format is projects/{project}.
array $optionalArgs { 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 Value

PagedListResponse

Exceptions

ApiException if the remote call fails

at line line 610
deleteSubscription(string $subscription, array $optionalArgs = array())

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.

Sample code:


try {
    $subscriberClient = new SubscriberClient();
    $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
    $subscriberClient->deleteSubscription($formattedSubscription);
} finally {
    if (isset($subscriberClient)) {
        $subscriberClient->close();
    }
}

Parameters

string $subscription The subscription to delete. Format is projects/{project}/subscriptions/{sub}.
array $optionalArgs { 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.

}

Exceptions

ApiException if the remote call fails

at line line 676
modifyAckDeadline(string $subscription, string[] $ackIds, int $ackDeadlineSeconds, array $optionalArgs = array())

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.

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();
    }
}

Parameters

string $subscription The name of the subscription. Format is projects/{project}/subscriptions/{sub}.
string[] $ackIds List of acknowledgment IDs.
int $ackDeadlineSeconds 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).
array $optionalArgs { 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.

}

Exceptions

ApiException if the remote call fails

at line line 741
acknowledge(string $subscription, string[] $ackIds, array $optionalArgs = array())

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.

Sample code:


try {
    $subscriberClient = new SubscriberClient();
    $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
    $ackIds = [];
    $subscriberClient->acknowledge($formattedSubscription, $ackIds);
} finally {
    if (isset($subscriberClient)) {
        $subscriberClient->close();
    }
}

Parameters

string $subscription The subscription whose message is being acknowledged. Format is projects/{project}/subscriptions/{sub}.
string[] $ackIds The acknowledgment ID for the messages being acknowledged that was returned by the Pub/Sub system in the Pull response. Must not be empty.
array $optionalArgs { 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.

}

Exceptions

ApiException if the remote call fails

at line line 811
PullResponse pull(string $subscription, int $maxMessages, array $optionalArgs = array())

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.

Sample code:


try {
    $subscriberClient = new SubscriberClient();
    $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
    $maxMessages = 0;
    $response = $subscriberClient->pull($formattedSubscription, $maxMessages);
} finally {
    if (isset($subscriberClient)) {
        $subscriberClient->close();
    }
}

Parameters

string $subscription The subscription from which messages should be pulled. Format is projects/{project}/subscriptions/{sub}.
int $maxMessages The maximum number of messages returned for this request. The Pub/Sub system may return fewer than the number specified.
array $optionalArgs { 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 Value

PullResponse

Exceptions

ApiException if the remote call fails

at line line 879
modifyPushConfig(string $subscription, PushConfig $pushConfig, array $optionalArgs = array())

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.

Sample code:


try {
    $subscriberClient = new SubscriberClient();
    $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
    $pushConfig = new PushConfig();
    $subscriberClient->modifyPushConfig($formattedSubscription, $pushConfig);
} finally {
    if (isset($subscriberClient)) {
        $subscriberClient->close();
    }
}

Parameters

string $subscription The name of the subscription. Format is projects/{project}/subscriptions/{sub}.
PushConfig $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.

array $optionalArgs { 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.

}

Exceptions

ApiException if the remote call fails

at line line 941
Policy setIamPolicy(string $resource, Policy $policy, array $optionalArgs = array())

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

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();
    }
}

Parameters

string $resource 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 $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.
array $optionalArgs { 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 Value

Policy

Exceptions

ApiException if the remote call fails

at line line 999
Policy getIamPolicy(string $resource, array $optionalArgs = array())

Gets the access control policy for a resource.

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();
    }
}

Parameters

string $resource 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}.
array $optionalArgs { 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 Value

Policy

Exceptions

ApiException if the remote call fails

at line line 1061
TestIamPermissionsResponse testIamPermissions(string $resource, string[] $permissions, array $optionalArgs = array())

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.

Sample code:


try {
    $subscriberClient = new SubscriberClient();
    $formattedResource = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]");
    $permissions = [];
    $response = $subscriberClient->testIamPermissions($formattedResource, $permissions);
} finally {
    if (isset($subscriberClient)) {
        $subscriberClient->close();
    }
}

Parameters

string $resource 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}.
string[] $permissions 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.
array $optionalArgs { 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 Value

TestIamPermissionsResponse

Exceptions

ApiException if the remote call fails

at line line 1089
close()

Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.