PHP Class Google\Cloud\PubSub\Topic

Example: use Google\Cloud\ServiceBuilder; $client = new ServiceBuilder(); $pubsub = $client->pubsub(); $topic = $pubsub->topic('my-new-topic'); You can also pass a fully-qualified topic name: $topic = $pubsub->topic('projects/my-awesome-project/topics/my-new-topic');
Inheritance: use trait ResourceNameTrait
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php Class Usage Examples

Protected Properties

Property Type Description
$connection A connection to the Google Cloud Platform API

Public Methods

Method Description
__construct ( Google\Cloud\PubSub\Connection\ConnectionInterface $connection, string $projectId, string $name, boolean $encode, array $info = null ) Create a PubSub topic.
__debugInfo ( ) : array Present a nicer debug result to people using php 5.6 or greater.
create ( array $options = [] ) : array Create a topic.
delete ( array $options = [] ) : void Delete a topic.
exists ( array $options = [] ) : boolean Check if a topic exists.
iam ( ) : Iam Manage the IAM policy for the current Topic.
info ( array $options = [] ) : array Get topic information.
name ( ) : string Get the topic name
publish ( array $message, array $options = [] ) : array Publish a new message to the topic.
publishBatch ( array $messages, array $options = [] ) : array Publish multiple messages at once.
reload ( array $options = [] ) : array Get topic information from the API.
subscribe ( string $name, array $options = [] ) : Subscription Create a subscription to the topic.
subscription ( string $name ) : Subscription This method will not run any API requests. You will receive a Subscription object that you can use to interact with the API.
subscriptions ( array $options = [] ) : Generator Retrieve a list of active subscriptions to the current topic.

Private Methods

Method Description
formatMessage ( array $message ) : array Ensure that the message is in a correct format, base64_encode the data, and error if the input is too wrong to proceed.
subscriptionFactory ( string $name, array $info = [] ) : Subscription Create a new subscription instance with the given name and optional subscription data.

Method Details

__construct() public method

Create a PubSub topic.
public __construct ( Google\Cloud\PubSub\Connection\ConnectionInterface $connection, string $projectId, string $name, boolean $encode, array $info = null )
$connection Google\Cloud\PubSub\Connection\ConnectionInterface A connection to the Google Cloud Platform service
$projectId string The project Id
$name string The topic name
$encode boolean Whether messages should be base64 encoded.
$info array [optional] A [Topic](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics)

__debugInfo() public method

Present a nicer debug result to people using php 5.6 or greater.
public __debugInfo ( ) : array
return array

create() public method

Example: $topicInfo = $topic->create();
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/create Create Topic
public create ( array $options = [] ) : array
$options array [optional] Configuration Options
return array Topic information

delete() public method

Example: $topic->delete();
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/delete Delete Topic
public delete ( array $options = [] ) : void
$options array [optional] Configuration Options
return void

exists() public method

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\Topic::info()}. Example: if ($topic->exists()) { echo 'Topic exists'; }
public exists ( array $options = [] ) : boolean
$options array [optional] Configuration Options
return boolean

iam() public method

Example: $iam = $topic->iam();
See also: https://cloud.google.com/pubsub/access_control PubSub Access Control Documentation
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/getIamPolicy Get Topic IAM Policy
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/setIamPolicy Set Topic IAM Policy
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/testIamPermissions Test Topic Permissions
public iam ( ) : Iam
return Google\Cloud\Iam\Iam

info() public method

Currently this resource returns only the topic name, if the topic exists. It is mostly useful therefore for checking if a topic exists. Since this method will throw an exception if the topic is not found, you may find that Topic::exists() is a better fit for a true/false check. This method will use the previously cached result, if available. To force a refresh from the API, use {@see \Google\Cloud\Pubsub\Topic::reload()}. Example: $info = $topic->info(); echo $info['name']; // projects/my-awesome-project/topics/my-new-topic
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/get Get Topic
public info ( array $options = [] ) : array
$options array [optional] Configuration Options
return array [A representation of a Topic](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics)

name() public method

Example: echo $topic->name();
public name ( ) : string
return string

publish() public method

$message must provide at least one of data and attributes members. Example: $topic->publish([ 'data' => 'New User Registered', 'attributes' => [ 'id' => 1, 'userName' => 'John', 'location' => 'Detroit' ] ]);
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/publish Publish Message
public publish ( array $message, array $options = [] ) : array
$message array [Message Format](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage)
$options array [optional] Configuration Options
return array A list of message IDs

publishBatch() public method

Example: $topic->publishBatch([ [ 'data' => 'New User Registered', 'attributes' => [ 'id' => 1, 'userName' => 'John', 'location' => 'Detroit' ] ], [ 'data' => 'New User Registered', 'attributes' => [ 'id' => 2, 'userName' => 'Steve', 'location' => 'Mountain View' ] ] ]);
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/publish Publish Message
public publishBatch ( array $messages, array $options = [] ) : array
$messages array A list of messages. Each message must be in the correct [Message Format](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage). If provided, $data will be base64 encoded before being published, unless `$options['encode']` is set to false. (See below for more information.) }
$options array [optional] Configuration Options
return array A list of message IDs.

reload() public method

Currently this resource returns only the topic name, if the topic exists. It is mostly useful therefore for checking if a topic exists. Since this method will throw an exception if the topic is not found, you may find that Topic::exists() is a better fit for a true/false check. This method will retrieve a new result from the API. To use a previously cached result, if one exists, use {@see \Google\Cloud\Pubsub\Topic::info()}. Example: $topic->reload(); $info = $topic->info(); echo $info['name']; // projects/my-awesome-project/topics/my-new-topic
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/get Get Topic
public reload ( array $options = [] ) : array
$options array [optional] Configuration Options
return array [A representation of a Topic](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics)

subscribe() public method

Example: $subscription = $topic->subscribe('my-new-subscription');
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create Create Subscription
public subscribe ( string $name, array $options = [] ) : Subscription
$name string The subscription name
$options array [optional] Please see {@see \Google\Cloud\PubSub\Subscription::create()} for configuration details.
return Subscription

subscription() public method

Example: $subscription = $topic->subscription('my-new-subscription');
public subscription ( string $name ) : Subscription
$name string The subscription name
return Subscription

subscriptions() public method

Example: $subscriptions = $topic->subscriptions(); foreach ($subscriptions as $subscription) { echo $subscription->name(); }
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics.subscriptions/list List Topic Subscriptions
public subscriptions ( array $options = [] ) : Generator
$options array [optional] { Configuration Options @type int $pageSize Maximum number of subscriptions to return. }
return Generator

Property Details

$connection protected_oe property

A connection to the Google Cloud Platform API
protected $connection