PHP Class Google\Cloud\PubSub\V1\PublisherClient

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 { $publisherClient = new PublisherClient(); $formattedName = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); $response = $publisherClient->createTopic($formattedName); } finally { if (isset($publisherClient)) { $publisherClient->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.
close ( ) Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.
createTopic ( string $name, array $optionalArgs = [] ) : google\pubsub\v1\Topic Creates the given topic with the given name.
deleteTopic ( string $topic, array $optionalArgs = [] ) Deletes the topic with the given name. Returns NOT_FOUND if the topic does not exist. After a topic is deleted, a new topic may be created with the same name; this is an entirely new topic with none of the old configuration or subscriptions. Existing subscriptions to this topic are not deleted, but their topic field is set to _deleted-topic_.
formatProjectName ( $project ) Formats a string containing the fully-qualified path to represent a project 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.
getTopic ( string $topic, array $optionalArgs = [] ) : google\pubsub\v1\Topic Gets the configuration of a topic.
listTopicSubscriptions ( string $topic, array $optionalArgs = [] ) : Google\GAX\PagedListResponse Lists the name of the subscriptions for this topic.
listTopics ( string $project, array $optionalArgs = [] ) : Google\GAX\PagedListResponse Lists matching topics.
parseProjectFromProjectName ( $projectName ) Parses the project from the given fully-qualified path which represents a project resource.
parseProjectFromTopicName ( $topicName ) Parses the project from the given fully-qualified path which represents a topic resource.
parseTopicFromTopicName ( $topicName ) Parses the topic from the given fully-qualified path which represents a topic resource.
publish ( string $topic, google\pubsub\v1\PubsubMessage[] $messages, array $optionalArgs = [] ) : google\pubsub\v1\PublishResponse Adds one or more messages to the topic. Returns NOT_FOUND if the topic does not exist. The message payload must not be empty; it must contain either a non-empty data field, or at least one attribute.
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 ( )
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. }

close() public method

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

createTopic() public method

Sample code: try { $publisherClient = new PublisherClient(); $formattedName = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); $response = $publisherClient->createTopic($formattedName); } finally { if (isset($publisherClient)) { $publisherClient->close(); } }
public createTopic ( string $name, array $optionalArgs = [] ) : google\pubsub\v1\Topic
$name string The name of the topic. It must have the format `"projects/{project}/topics/{topic}"`. `{topic}` 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"`.
$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\Topic

deleteTopic() public method

Sample code: try { $publisherClient = new PublisherClient(); $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); $publisherClient->deleteTopic($formattedTopic); } finally { if (isset($publisherClient)) { $publisherClient->close(); } }
public deleteTopic ( string $topic, array $optionalArgs = [] )
$topic string Name of the topic to delete. Format is `projects/{project}/topics/{topic}`.
$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 )

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 { $publisherClient = new PublisherClient(); $formattedResource = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); $response = $publisherClient->getIamPolicy($formattedResource); } finally { if (isset($publisherClient)) { $publisherClient->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

getTopic() public method

Sample code: try { $publisherClient = new PublisherClient(); $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); $response = $publisherClient->getTopic($formattedTopic); } finally { if (isset($publisherClient)) { $publisherClient->close(); } }
public getTopic ( string $topic, array $optionalArgs = [] ) : google\pubsub\v1\Topic
$topic string The name of the topic to get. Format is `projects/{project}/topics/{topic}`.
$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\Topic

listTopicSubscriptions() public method

Sample code: try { $publisherClient = new PublisherClient(); $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); foreach ($publisherClient->listTopicSubscriptions($formattedTopic) as $element) { doThingsWith(element); } } finally { if (isset($publisherClient)) { $publisherClient->close(); } }
public listTopicSubscriptions ( string $topic, array $optionalArgs = [] ) : Google\GAX\PagedListResponse
$topic string The name of the topic that subscriptions are attached to. Format is `projects/{project}/topics/{topic}`.
$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

listTopics() public method

Sample code: try { $publisherClient = new PublisherClient(); $formattedProject = PublisherClient::formatProjectName("[PROJECT]"); foreach ($publisherClient->listTopics($formattedProject) as $element) { doThingsWith(element); } } finally { if (isset($publisherClient)) { $publisherClient->close(); } }
public listTopics ( string $project, array $optionalArgs = [] ) : Google\GAX\PagedListResponse
$project string The name of the cloud project that topics 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

parseProjectFromProjectName() public static method

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

parseProjectFromTopicName() public static method

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

parseTopicFromTopicName() public static method

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

publish() public method

Sample code: try { $publisherClient = new PublisherClient(); $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); $data = ""; $messagesElement = new PubsubMessage(); $messagesElement->setData($data); $messages = [$messagesElement]; $response = $publisherClient->publish($formattedTopic, $messages); } finally { if (isset($publisherClient)) { $publisherClient->close(); } }
public publish ( string $topic, google\pubsub\v1\PubsubMessage[] $messages, array $optionalArgs = [] ) : google\pubsub\v1\PublishResponse
$topic string The messages in the request will be published on this topic. Format is `projects/{project}/topics/{topic}`.
$messages google\pubsub\v1\PubsubMessage[] The messages to publish.
$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\PublishResponse

setIamPolicy() public method

Sample code: try { $publisherClient = new PublisherClient(); $formattedResource = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); $policy = new Policy(); $response = $publisherClient->setIamPolicy($formattedResource, $policy); } finally { if (isset($publisherClient)) { $publisherClient->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 { $publisherClient = new PublisherClient(); $formattedResource = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); $permissions = []; $response = $publisherClient->testIamPermissions($formattedResource, $permissions); } finally { if (isset($publisherClient)) { $publisherClient->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