class PublisherClient

Service Description: The service that an application uses to manipulate topics, and to send messages to a topic.

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.

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 
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 
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.

createTopic(string $name, array $optionalArgs = array())

Creates the given topic with the given name.

publish(string $topic, PubsubMessage[] $messages, array $optionalArgs = array())

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.

getTopic(string $topic, array $optionalArgs = array())

Gets the configuration of a topic.

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

Lists matching topics.

listTopicSubscriptions(string $topic, array $optionalArgs = array())

Lists the name of the subscriptions for this topic.

deleteTopic(string $topic, array $optionalArgs = array())

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_.

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 105
static formatProjectName($project)

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

Parameters

$project

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

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

Parameters

$project
$topic

at line line 128
static parseProjectFromProjectName($projectName)

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

Parameters

$projectName

at line line 137
static parseProjectFromTopicName($topicName)

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

Parameters

$topicName

at line line 146
static parseTopicFromTopicName($topicName)

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

Parameters

$topicName

at line line 227
__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 347
Topic createTopic(string $name, array $optionalArgs = array())

Creates the given topic with the given name.

Sample code:


try {
    $publisherClient = new PublisherClient();
    $formattedName = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]");
    $response = $publisherClient->createTopic($formattedName);
} finally {
    if (isset($publisherClient)) {
        $publisherClient->close();
    }
}

Parameters

string $name 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".
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

Topic

Exceptions

ApiException if the remote call fails

at line line 408
PublishResponse publish(string $topic, PubsubMessage[] $messages, array $optionalArgs = array())

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.

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

Parameters

string $topic The messages in the request will be published on this topic. Format is projects/{project}/topics/{topic}.
PubsubMessage[] $messages The messages to publish.
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

PublishResponse

Exceptions

ApiException if the remote call fails

at line line 465
Topic getTopic(string $topic, array $optionalArgs = array())

Gets the configuration of a topic.

Sample code:


try {
    $publisherClient = new PublisherClient();
    $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]");
    $response = $publisherClient->getTopic($formattedTopic);
} finally {
    if (isset($publisherClient)) {
        $publisherClient->close();
    }
}

Parameters

string $topic The name of the topic to get. Format is projects/{project}/topics/{topic}.
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

Topic

Exceptions

ApiException if the remote call fails

at line line 530
PagedListResponse listTopics(string $project, array $optionalArgs = array())

Lists matching topics.

Sample code:


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

Parameters

string $project The name of the cloud project that topics 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 601
PagedListResponse listTopicSubscriptions(string $topic, array $optionalArgs = array())

Lists the name of the subscriptions for this topic.

Sample code:


try {
    $publisherClient = new PublisherClient();
    $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]");
    foreach ($publisherClient->listTopicSubscriptions($formattedTopic)->iterateAllElements() as $element) {
        // doThingsWith(element);
    }
} finally {
    if (isset($publisherClient)) {
        $publisherClient->close();
    }
}

Parameters

string $topic The name of the topic that subscriptions are attached to. Format is projects/{project}/topics/{topic}.
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 663
deleteTopic(string $topic, array $optionalArgs = array())

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_.

Sample code:


try {
    $publisherClient = new PublisherClient();
    $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]");
    $publisherClient->deleteTopic($formattedTopic);
} finally {
    if (isset($publisherClient)) {
        $publisherClient->close();
    }
}

Parameters

string $topic Name of the topic to delete. Format is projects/{project}/topics/{topic}.
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 724
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 {
    $publisherClient = new PublisherClient();
    $formattedResource = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]");
    $policy = new Policy();
    $response = $publisherClient->setIamPolicy($formattedResource, $policy);
} finally {
    if (isset($publisherClient)) {
        $publisherClient->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 782
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 {
    $publisherClient = new PublisherClient();
    $formattedResource = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]");
    $response = $publisherClient->getIamPolicy($formattedResource);
} finally {
    if (isset($publisherClient)) {
        $publisherClient->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 844
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 {
    $publisherClient = new PublisherClient();
    $formattedResource = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]");
    $permissions = [];
    $response = $publisherClient->testIamPermissions($formattedResource, $permissions);
} finally {
    if (isset($publisherClient)) {
        $publisherClient->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 872
close()

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