Reference documentation and code samples for the Cloud PubSub Client class Topic.
A named resource to which messages are sent by publishers.
Example:
use Google\Cloud\PubSub\PubSubClient;
$pubsub = new PubSubClient(['projectId' => 'my-awesome-project']);
$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');
Namespace
Google \ Cloud \ PubSubMethods
__construct
Create a PubSub topic.
requestHandler
Google\Cloud\Core\RequestHandler
serializer
projectId
string
The project Id
name
string
The topic name
encode
bool
Whether messages should be base64 encoded.
info
↳ name
string
The name of the topic.
↳ labels
array
Key value pairs used to organize your resources.
↳ kmsKeyName
string
The resource name of the Cloud KMS CryptoKey to be used to protect access to messages published on this topic. The expected format is projects/my-project/locations/kr-location/keyRings/my-kr/cryptoKeys/my-key
.
↳ enableCompression
bool
Flag to enable compression of messages before publishing. Set the flag to true
to enable compression. Defaults to false
. Messsages are compressed if their total size >= compressionBytesThreshold
, whose default value has been experimentally derived after performance evaluations.
↳ compressionBytesThreshold
int
The threshold byte size above which messages are compressed. This only takes effect if enableCompression
is set to true
. Defaults to 240
. (This value is experiementally derived after performance evaluations.)
clientConfig
array
[optional] Configuration options for the PubSub client used to handle processing of batch items through the daemon. For valid options please see PubSubClient::__construct() . Defaults to * the options provided to the PubSub client associated with this instance.
name
Get the topic name
Example:
echo $topic->name();
string
create
See also:
options
array
Configuration Options
↳ labels
array
Key value pairs used to organize your resources.
↳ kmsKeyName
string
The resource name of the Cloud KMS CryptoKey to be used to protect access to messages published on this topic. The expected format is projects/my-project/locations/kr-location/keyRings/my-kr/cryptoKeys/my-key
.
↳ messageStoragePolicy
array
Policy constraining the set of Google Cloud Platform regions where messages published to the topic may be stored. If not present, then no constraints are in effect.
allowedPersistenceRegions
string[]
A list of IDs of GCP regions where messages that are published to the topic may be persisted in storage. Messages published by publishers running in non-allowed GCP regions (or running outside of GCP altogether) will be routed for storage in one of the allowed regions. An empty list means that no regions are allowed, and is not a valid configuration.
↳ schemaSettings.schema
string|Schema
The name of a schema that messages published should be validated against, or an instance of Schema .
↳ schemaSettings.encoding
string
The encoding of messages validated against schema. For allowed values, see constants defined on V1\Encoding}. </xref
array
update
See also:
data
array
The Topic data.
↳ labels
array
Key value pairs used to organize your resources.
↳ messageStoragePolicy
array
Policy constraining the set of Google Cloud Platform regions where messages published to the topic may be stored. If not present, then no constraints are in effect.
allowedPersistenceRegions
string[]
A list of IDs of GCP regions where messages that are published to the topic may be persisted in storage. Messages published by publishers running in non-allowed GCP regions (or running outside of GCP altogether) will be routed for storage in one of the allowed regions. An empty list means that no regions are allowed, and is not a valid configuration.
↳ schemaSettings.schema
string|Schema
The name of a schema that messages published should be validated against, or an instance of Schema .
↳ schemaSettings.encoding
string
The encoding of messages validated against schema. For allowed values, see constants defined on V1\Encoding}. </xref
options
array
Configuration options.
↳ updateMask
array
A list of field paths to be modified. Nested key names should be dot-separated, e.g. messageStoragePolicy.allowedPersistenceRegions
. Google Cloud PHP will attempt to infer this value on your behalf, however modification of map fields with arbitrary keys (such as labels or message storage policy) requires an explicit update mask.
array
delete
See also:
options
array
[optional] Configuration Options
void
exists
Check if a topic 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 Topic::info() .
Example:
if ($topic->exists()) {
echo 'Topic exists';
}
options
array
[optional] Configuration Options
bool
info
See also:
options
array
[optional] Configuration Options
array
reload
See also:
options
array
[optional] Configuration Options
array
publish
See also:
message
options
array
[optional] Configuration Options
array
publishBatch
See also:
messages
array< Message
>|array[]
A list of messages. Each message must be in the correct Message Format , or be an instance of Message .
options
array
[optional] Configuration Options
array
batchPublisher
Push a message into a batch queue, to be processed at a later point.
Example:
$topic->batchPublisher()
->publish([
'data' => 'New User Registered',
'attributes' => [
'id' => '2',
'userName' => 'Dave',
'location' => 'Detroit'
]
]);
options
array
Configuration options.
↳ debugOutput
bool
Whether or not to output debug information. Please note debug output currently only applies in CLI based applications. Defaults to false
.
↳ debugOutputResource
resource
A resource to output debug output to. Defaults toResource for php://stderr
.
↳ batchOptions
array
A set of options for a BatchJob. Google\Cloud\Core\Batch\BatchJob::__construct() for more details. Defaults to['batchSize' => 1000, 'callPeriod' => 2.0, 'numWorkers' => 2].
↳ clientConfig
array
Configuration options for the PubSub client used to handle processing of batch items. For valid options please see PubSubClient::__construct()
. Defaults tothe options provided to the client associated with the current Topic
instance.
↳ batchRunner
BatchRunner
A BatchRunner object. Mainly used for the tests to inject a mock. Defaults toa newly created BatchRunner.
↳ identifier
string
An identifier for the batch job. Defaults to pubsub-topic-{topic-name}
. Example: pubsub-topic-mytopic
.
↳ closureSerializer
ClosureSerializerInterface
An implementation responsible for serializing closures used in the $clientConfig
. This is especially important when using the batch daemon. Defaults to Google\Cloud\Core\Batch\OpisClosureSerializer
if the opis/closure
library is installed.
↳ enableCompression
bool
Flag to enable compression of messages before publishing. Set the flag to true
to enable compression. Defaults to false
. Messsages are compressed if their total size >= compressionBytesThreshold
, whose default value has been experimentally derived after performance evaluations.
↳ compressionBytesThreshold
int
The threshold byte size above which messages are compressed. This only takes effect if enableCompression
is set to true
. Defaults to 240
. (This value is experiementally derived after performance evaluations.)
subscribe
See also:
name
string
The subscription name
options
subscription
This method will not run any API requests. You will receive a Subscription object that you can use to interact with the API.
Example:
$subscription = $topic->subscription('my-new-subscription');
name
string
The subscription name
subscriptions
See also:
options
array
Configuration Options
↳ pageSize
int
Maximum number of subscriptions to return.
↳ resultLimit
int
Limit the number of results returned in total. Defaults to 0
(return all results).
↳ pageToken
string
A previously-returned page token used to resume the loading of results from a specific point.
iam
See also:
Google\Cloud\Core\Iam\IamManager
__debugInfo
Present a nicer debug result to people using php 5.6 or greater.
array
Constants
DEFAULT_COMPRESSION_BYTES_THRESHOLD
Value: 240
DEFAULT_ENABLE_COMPRESSION
Value: false