PHP Класс Google\Cloud\PubSub\Subscription

Example: Create subscription through a topic use Google\Cloud\ServiceBuilder; $cloud = new ServiceBuilder(); $pubsub = $cloud->pubsub(); $topic = $pubsub->topic('my-topic-name'); $subscription = $topic->subscription('my-new-subscription'); Create subscription through PubSubClient use Google\Cloud\PubSub\PubSubClient; $pubsub = new PubSubClient([ 'projectId' => 'my-awesome-project' ]); $subscription = $pubsub->subscription( 'my-new-subscription', 'my-topic-name' );
Наследование: use trait ResourceNameTrait
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$connection Google\Cloud\PubSub\Connection\ConnectionInterface

Открытые методы

Метод Описание
__construct ( Google\Cloud\PubSub\Connection\ConnectionInterface $connection, string $projectId, string $name, string $topicName, boolean $encode, array $info = null ) Create a Subscription.
__debugInfo ( ) : array Present a nicer debug result to people using php 5.6 or greater.
acknowledge ( Message $message, array $options = [] ) : void Acknowledge receipt of a message.
acknowledgeBatch ( array $messages, array $options = [] ) : void Acknowledge receipt of multiple messages at once.
create ( array $options = [] ) : array Execute a service request creating the subscription.
delete ( array $options = [] ) : void Delete a subscription
exists ( array $options = [] ) : boolean Check if a subscription exists.
iam ( ) : Iam Manage the IAM policy for the current Subscription.
info ( array $options = [] ) : array Get info on a subscription
modifyAckDeadline ( Message $message, integer $seconds, array $options = [] ) : void Set the acknowledge deadline for a single ackId.
modifyAckDeadlineBatch ( array $messages, integer $seconds, array $options = [] ) : void Set the acknowledge deadline for multiple ackIds.
modifyPushConfig ( array $pushConfig, array $options = [] ) : void Set the push config for the subscription
name ( ) : string Get the subscription name
pull ( array $options = [] ) : Generator Retrieve new messages from the topic.
reload ( array $options = [] ) : array Retrieve info on a subscription from the API.

Приватные методы

Метод Описание
getMessageAckIds ( array $messages ) : array Get a list of ackIds from a list of Message objects.

Описание методов

__construct() публичный метод

The idiomatic way to use this class is through the PubSubClient or Topic, but you can instantiate it directly as well.
public __construct ( Google\Cloud\PubSub\Connection\ConnectionInterface $connection, string $projectId, string $name, string $topicName, boolean $encode, array $info = null )
$connection Google\Cloud\PubSub\Connection\ConnectionInterface The service connection object
$projectId string The current project
$name string The subscription name
$topicName string The topic name the subscription is attached to
$encode boolean Whether messages are encrypted or not.
$info array [optional] Subscription info. Used to pre-populate the object.

__debugInfo() публичный метод

Present a nicer debug result to people using php 5.6 or greater.
public __debugInfo ( ) : array
Результат array

acknowledge() публичный метод

Use {@see \Google\Cloud\PubSub\Subscription::acknowledgeBatch()} to acknowledge multiple messages at once. Example: $messages = $subscription->pull(); $messagesArray = iterator_to_array($messages); $subscription->acknowledge($messagesArray[0]);
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/acknowledge Acknowledge Message
public acknowledge ( Message $message, array $options = [] ) : void
$message Message A message object.
$options array [optional] Configuration Options
Результат void

acknowledgeBatch() публичный метод

Use {@see \Google\Cloud\PubSub\Subscription::acknowledge()} to acknowledge a single message. Example: $messages = $subscription->pull(); $messagesArray = iterator_to_array($messages); $subscription->acknowledgeBatch($messagesArray);
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/acknowledge Acknowledge Message
public acknowledgeBatch ( array $messages, array $options = [] ) : void
$messages array An array of messages
$options array Configuration Options
Результат void

create() публичный метод

The suggested way of creating a subscription is by calling through {@see \Google\Cloud\PubSub\Topic::subscribe()} or {@see \Google\Cloud\PubSub\Topic::subscription()}. Returns subscription info in the format detailed in the documentation for a subscription. **NOTE: Some methods of instantiation of a Subscription do not supply a topic name. The topic name is required to create a subscription.** Example: $topic = $pubsub->topic('my-new-topic'); $subscription = $topic->subscription('my-new-subscription'); $result = $subscription->create();
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create Create Subscription
public create ( array $options = [] ) : array
$options array [optional] { Configuration Options @type int $ackDeadlineSeconds This value is the maximum time after a subscriber receives a message before the subscriber should acknowledge the message. **Defaults to** `10`. @type array $pushConfig See {@see \Google\Cloud\PubSub\Subscription::modifyPushConfig()} or [PushConfig](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions#PushConfig) for usage. }
Результат array An array of subscription info

delete() публичный метод

Example: $subscription->delete();
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/delete Delete Subscription
public delete ( array $options = [] ) : void
$options array [optional] Configuration Options.
Результат void

exists() публичный метод

Service errors will NOT bubble up from this method. It will always return a boolean value. If you want to check for errors, use {@see \Google\Cloud\PubSub\Subscription::info()}. If you need to re-check the existence of a subscription that is already downloaded, call {@see \Google\Cloud\PubSub\Subscription::reload()} first to refresh the cached information. Example: if ($subscription->exists()) { echo 'Subscription exists!'; }
public exists ( array $options = [] ) : boolean
$options array [optional] Configuration Options
Результат boolean

iam() публичный метод

Example: $iam = $subscription->iam();
См. также: https://cloud.google.com/pubsub/access_control PubSub Access Control Documentation
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/getIamPolicy Get Subscription IAM Policy
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/setIamPolicy Set Subscription IAM Policy
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/testIamPermissions Test Subscription Permissions
public iam ( ) : Iam
Результат Google\Cloud\Iam\Iam

info() публичный метод

If the info is already cached on the object, it will return that result. To fetch a fresh result, use {@see \Google\Cloud\PubSub\Subscription::reload()}. Example: $info = $subscription->info(); echo $info['name']; // projects/my-awesome-project/subscriptions/my-new-subscription
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/get Get Subscription
public info ( array $options = [] ) : array
$options array [optional] Configuration Options
Результат array Subscription data

modifyAckDeadline() публичный метод

Use {@see \Google\Cloud\PubSub\Subscription::modifyAckDeadlineBatch()} to modify the ack deadline for multiple messages at once. Example: $messages = $subscription->pull(); foreach ($messages as $message) { $subscription->modifyAckDeadline($message, 3); sleep(2); Now we'll acknowledge! $subscription->acknowledge($message); break; }
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/modifyAckDeadline Modify Ack Deadline
public modifyAckDeadline ( Message $message, integer $seconds, array $options = [] ) : void
$message Message A message object
$seconds integer The new ack deadline with respect to the time this request was sent to the Pub/Sub system. Must be >= 0. 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.
$options array [optional] Configuration Options
Результат void

modifyAckDeadlineBatch() публичный метод

Use {@see \Google\Cloud\PubSub\Subscription::modifyAckDeadline()} to modify the ack deadline for a single message. Example: $messages = $subscription->pull(); $messagesArray = iterator_to_array($messages); Set the ack deadline to a minute and a half from now for every message $subscription->modifyAckDeadlineBatch($messagesArray, 3); Delay execution, or make a sandwich or something. sleep(2); Now we'll acknowledge $subscription->acknowledge($messagesArray);
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/modifyAckDeadline Modify Ack Deadline
public modifyAckDeadlineBatch ( array $messages, integer $seconds, array $options = [] ) : void
$messages array An array of messages
$seconds integer The new ack deadline with respect to the time this request was sent to the Pub/Sub system. Must be >= 0. 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.
$options array [optional] Configuration Options
Результат void

modifyPushConfig() публичный метод

Example: $subscription->modifyPushConfig([ 'pushEndpoint' => 'https://www.example.com/foo/bar' ]);
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/modifyPushConfig Modify Push Config
public modifyPushConfig ( array $pushConfig, array $options = [] ) : void
$pushConfig array { Push delivery configuration. See [PushConfig](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions#PushConfig) for more details. @type string $pushEndpoint A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use "https://example.com/push". @type array $attributes Endpoint configuration attributes. }
$options array [optional] Configuration Options
Результат void

name() публичный метод

Example: echo $subscription->name();
public name ( ) : string
Результат string

pull() публичный метод

Example: $messages = $subscription->pull(); foreach ($messages as $message) { echo $message->data(); }
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/pull Pull Subscriptions
public pull ( array $options = [] ) : Generator
$options array [optional] { Configuration Options @type bool $returnImmediately If set, the system will respond immediately, even if no messages are available. Otherwise, wait until new messages are available. @type int $maxMessages Limit the amount of messages pulled. }
Результат Generator

reload() публичный метод

To use the previously cached result (if it exists), use {@see \Subscription::info()}. Example: $subscription->reload(); $info = $subscription->info(); echo $info['name']; // projects/my-awesome-project/subscriptions/my-new-subscription
См. также: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/get Get Subscription
public reload ( array $options = [] ) : array
$options array [optional] Configuration Options
Результат array Subscription data

Описание свойств

$connection защищенное свойство

protected ConnectionInterface,Google\Cloud\PubSub\Connection $connection
Результат Google\Cloud\PubSub\Connection\ConnectionInterface