SubscriberClient
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
Formats a string containing the fully-qualified path to represent a project resource.
Formats a string containing the fully-qualified path to represent a subscription resource.
Formats a string containing the fully-qualified path to represent a topic resource.
Parses the project from the given fully-qualified path which represents a project resource.
Parses the project from the given fully-qualified path which represents a subscription resource.
Parses the subscription from the given fully-qualified path which represents a subscription resource.
Parses the project from the given fully-qualified path which represents a topic resource.
Parses the topic from the given fully-qualified path which represents a topic resource.
Constructor.
Creates a subscription to a given topic.
Gets the configuration details of a subscription.
Lists matching subscriptions.
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.
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.
Acknowledges the messages associated with the ack_ids
in the
AcknowledgeRequest
. The Pub/Sub system can remove the relevant messages
from the subscription.
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.
Modifies the PushConfig
for a specified subscription.
Sets the access control policy on the specified resource. Replaces any existing policy.
Gets the access control policy for a resource.
Returns permissions that a caller has on the specified resource.
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.
at line line 120
static
formatSubscriptionName($project, $subscription)
Formats a string containing the fully-qualified path to represent a subscription resource.
at line line 132
static
formatTopicName($project, $topic)
Formats a string containing the fully-qualified path to represent a topic resource.
at line line 144
static
parseProjectFromProjectName($projectName)
Parses the project from the given fully-qualified path which represents a project resource.
at line line 153
static
parseProjectFromSubscriptionName($subscriptionName)
Parses the project from the given fully-qualified path which represents a subscription resource.
at line line 162
static
parseSubscriptionFromSubscriptionName($subscriptionName)
Parses the subscription from the given fully-qualified path which represents a subscription resource.
at line line 171
static
parseProjectFromTopicName($topicName)
Parses the project from the given fully-qualified path which represents a topic resource.
at line line 180
static
parseTopicFromTopicName($topicName)
Parses the topic from the given fully-qualified path which represents a topic resource.
at line line 262
__construct(array $options = array())
Constructor.
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
at line line 1089
close()
Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.