Reference documentation and code samples for the Cloud PubSub V1 Client class Topic.
A topic resource.
Generated from protobuf messagegoogle.pubsub.v1.Topic
Namespace
Google \ Cloud \ PubSub \ V1
Methods
__construct
Constructor.
Parameters
Name
Description
data
array
Optional. Data for populating the Message object.
↳ name
string
Required. 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".
Optional. 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.
↳ kms_key_name
string
Optional. The resource name of the Cloud KMS CryptoKey to be used to protect access to messages published on this topic. The expected format isprojects/*/locations/*/keyRings/*/cryptoKeys/*.
Optional. Indicates the minimum duration to retain a message after it is published to the topic. If this field is set, messages published to the topic in the lastmessage_retention_durationare always available to subscribers. For instance, it allows any attached subscription toseek to a timestampthat is up tomessage_retention_durationin the past. If this field is not set, message retention is controlled by settings on individual subscriptions. Cannot be more than 31 days or less than 10 minutes.
↳ state
int
Output only. An output-only field indicating the state of the topic.
Optional. Transforms to be applied to messages published to the topic. Transforms are applied in the order specified.
getName
Required. 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".
Returns
Type
Description
string
setName
Required. 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".
Optional. 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.
Optional. 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.
Optional. Reserved for future use. This field is set only in responses from
the server; it is ignored if it is set in any requests.
Returns
Type
Description
bool
setSatisfiesPzs
Optional. Reserved for future use. This field is set only in responses from
the server; it is ignored if it is set in any requests.
Parameter
Name
Description
var
bool
Returns
Type
Description
$this
getMessageRetentionDuration
Optional. Indicates the minimum duration to retain a message after it is
published to the topic. If this field is set, messages published to the
topic in the lastmessage_retention_durationare always available to
subscribers. For instance, it allows any attached subscription toseek to
a
timestampthat is up tomessage_retention_durationin the past. If this field is
not set, message retention is controlled by settings on individual
subscriptions. Cannot be more than 31 days or less than 10 minutes.
Optional. Indicates the minimum duration to retain a message after it is
published to the topic. If this field is set, messages published to the
topic in the lastmessage_retention_durationare always available to
subscribers. For instance, it allows any attached subscription toseek to
a
timestampthat is up tomessage_retention_durationin the past. If this field is
not set, message retention is controlled by settings on individual
subscriptions. Cannot be more than 31 days or less than 10 minutes.
Required. 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".
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud PubSub V1 Client - Class Topic (2.13.2)\n\nVersion latestkeyboard_arrow_down\n\n- [2.13.2 (latest)](/php/docs/reference/cloud-pubsub/latest/V1.Topic)\n- [2.13.1](/php/docs/reference/cloud-pubsub/2.13.1/V1.Topic)\n- [2.12.0](/php/docs/reference/cloud-pubsub/2.12.0/V1.Topic)\n- [2.11.3](/php/docs/reference/cloud-pubsub/2.11.3/V1.Topic)\n- [2.10.1](/php/docs/reference/cloud-pubsub/2.10.1/V1.Topic)\n- [2.9.1](/php/docs/reference/cloud-pubsub/2.9.1/V1.Topic)\n- [2.8.2](/php/docs/reference/cloud-pubsub/2.8.2/V1.Topic)\n- [2.7.0](/php/docs/reference/cloud-pubsub/2.7.0/V1.Topic)\n- [2.6.0](/php/docs/reference/cloud-pubsub/2.6.0/V1.Topic)\n- [2.5.2](/php/docs/reference/cloud-pubsub/2.5.2/V1.Topic)\n- [2.4.0](/php/docs/reference/cloud-pubsub/2.4.0/V1.Topic)\n- [2.3.0](/php/docs/reference/cloud-pubsub/2.3.0/V1.Topic)\n- [2.2.1](/php/docs/reference/cloud-pubsub/2.2.1/V1.Topic)\n- [2.1.2](/php/docs/reference/cloud-pubsub/2.1.2/V1.Topic)\n- [1.50.0](/php/docs/reference/cloud-pubsub/1.50.0/V1.Topic)\n- [1.49.0](/php/docs/reference/cloud-pubsub/1.49.0/V1.Topic)\n- [1.48.0](/php/docs/reference/cloud-pubsub/1.48.0/V1.Topic)\n- [1.47.0](/php/docs/reference/cloud-pubsub/1.47.0/V1.Topic)\n- [1.46.5](/php/docs/reference/cloud-pubsub/1.46.5/V1.Topic)\n- [1.45.2](/php/docs/reference/cloud-pubsub/1.45.2/V1.Topic)\n- [1.44.0](/php/docs/reference/cloud-pubsub/1.44.0/V1.Topic)\n- [1.43.2](/php/docs/reference/cloud-pubsub/1.43.2/V1.Topic)\n- [1.42.1](/php/docs/reference/cloud-pubsub/1.42.1/V1.Topic)\n- [1.41.3](/php/docs/reference/cloud-pubsub/1.41.3/V1.Topic)\n- [1.40.1](/php/docs/reference/cloud-pubsub/1.40.1/V1.Topic)\n- [1.39.3](/php/docs/reference/cloud-pubsub/1.39.3/V1.Topic) \nReference documentation and code samples for the Cloud PubSub V1 Client class Topic.\n\nA topic resource.\n\nGenerated from protobuf message `google.pubsub.v1.Topic`\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ PubSub \\\\ V1\n\nMethods\n-------\n\n### __construct\n\nConstructor.\n\n### getName\n\nRequired. The name of the topic. It must have the format\n`\"projects/{project}/topics/{topic}\"`. `{topic}` must start with a letter,\nand contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),\nunderscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent\nsigns (`%`). It must be between 3 and 255 characters in length, and it\nmust not start with `\"goog\"`.\n\n### setName\n\nRequired. The name of the topic. It must have the format\n`\"projects/{project}/topics/{topic}\"`. `{topic}` must start with a letter,\nand contain only letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`),\nunderscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent\nsigns (`%`). It must be between 3 and 255 characters in length, and it\nmust not start with `\"goog\"`.\n\n### getLabels\n\nOptional. See [Creating and managing labels](https://cloud.google.com/pubsub/docs/labels).\n\n### setLabels\n\nOptional. See [Creating and managing labels](https://cloud.google.com/pubsub/docs/labels).\n\n### getMessageStoragePolicy\n\nOptional. Policy constraining the set of Google Cloud Platform regions\nwhere messages published to the topic may be stored. If not present, then\nno constraints are in effect.\n\n### hasMessageStoragePolicy\n\n### clearMessageStoragePolicy\n\n### setMessageStoragePolicy\n\nOptional. Policy constraining the set of Google Cloud Platform regions\nwhere messages published to the topic may be stored. If not present, then\nno constraints are in effect.\n\n### getKmsKeyName\n\nOptional. The resource name of the Cloud KMS CryptoKey to be used to\nprotect access to messages published on this topic.\n\nThe expected format is `projects/*/locations/*/keyRings/*/cryptoKeys/*`.\n\n### setKmsKeyName\n\nOptional. The resource name of the Cloud KMS CryptoKey to be used to\nprotect access to messages published on this topic.\n\nThe expected format is `projects/*/locations/*/keyRings/*/cryptoKeys/*`.\n\n### getSchemaSettings\n\nOptional. Settings for validating messages published against a schema.\n\n### hasSchemaSettings\n\n### clearSchemaSettings\n\n### setSchemaSettings\n\nOptional. Settings for validating messages published against a schema.\n\n### getSatisfiesPzs\n\nOptional. Reserved for future use. This field is set only in responses from\nthe server; it is ignored if it is set in any requests.\n\n### setSatisfiesPzs\n\nOptional. Reserved for future use. This field is set only in responses from\nthe server; it is ignored if it is set in any requests.\n\n### getMessageRetentionDuration\n\nOptional. Indicates the minimum duration to retain a message after it is\npublished to the topic. If this field is set, messages published to the\ntopic in the last `message_retention_duration` are always available to\nsubscribers. For instance, it allows any attached subscription to [seek to\na\ntimestamp](https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time)\nthat is up to `message_retention_duration` in the past. If this field is\nnot set, message retention is controlled by settings on individual\nsubscriptions. Cannot be more than 31 days or less than 10 minutes.\n\n### hasMessageRetentionDuration\n\n### clearMessageRetentionDuration\n\n### setMessageRetentionDuration\n\nOptional. Indicates the minimum duration to retain a message after it is\npublished to the topic. If this field is set, messages published to the\ntopic in the last `message_retention_duration` are always available to\nsubscribers. For instance, it allows any attached subscription to [seek to\na\ntimestamp](https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time)\nthat is up to `message_retention_duration` in the past. If this field is\nnot set, message retention is controlled by settings on individual\nsubscriptions. Cannot be more than 31 days or less than 10 minutes.\n\n### getState\n\nOutput only. An output-only field indicating the state of the topic.\n\n### setState\n\nOutput only. An output-only field indicating the state of the topic.\n\n### getIngestionDataSourceSettings\n\nOptional. Settings for ingestion from a data source into this topic.\n\n### hasIngestionDataSourceSettings\n\n### clearIngestionDataSourceSettings\n\n### setIngestionDataSourceSettings\n\nOptional. Settings for ingestion from a data source into this topic.\n\n### getMessageTransforms\n\nOptional. Transforms to be applied to messages published to the topic.\n\nTransforms are applied in the order specified.\n\n### setMessageTransforms\n\nOptional. Transforms to be applied to messages published to the topic.\n\nTransforms are applied in the order specified.\n\n### static::build"]]