PublisherClient
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
Formats a string containing the fully-qualified path to represent a project 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 topic resource.
Parses the topic from the given fully-qualified path which represents a topic resource.
Constructor.
Creates the given topic with the given name.
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.
Lists matching topics.
Lists the name of the subscriptions for this topic.
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_
.
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 105
static
formatProjectName($project)
Formats a string containing the fully-qualified path to represent a project resource.
at line line 116
static
formatTopicName($project, $topic)
Formats a string containing the fully-qualified path to represent a topic resource.
at line line 128
static
parseProjectFromProjectName($projectName)
Parses the project from the given fully-qualified path which represents a project resource.
at line line 137
static
parseProjectFromTopicName($topicName)
Parses the project from the given fully-qualified path which represents a topic resource.
at line line 146
static
parseTopicFromTopicName($topicName)
Parses the topic from the given fully-qualified path which represents a topic resource.
at line line 227
__construct(array $options = array())
Constructor.
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
at line line 872
close()
Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.