Skip to main content

topics

Creates, updates, deletes, gets or lists a topics resource.

Overview

Nametopics
TypeResource
Idgoogle.pubsub.topics

Fields

The following fields are returned by SELECT queries:

Successful response

NameDatatypeDescription
namestringRequired. 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".
ingestionDataSourceSettingsobjectOptional. Settings for ingestion from a data source into this topic. (id: IngestionDataSourceSettings)
kmsKeyNamestringOptional. 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/*/locations/*/keyRings/*/cryptoKeys/*.
labelsobjectOptional. See [Creating and managing labels] (https://cloud.google.com/pubsub/docs/labels).
messageRetentionDurationstring (google-duration)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 last message_retention_duration are always available to subscribers. For instance, it allows any attached subscription to seek to a timestamp that is up to message_retention_duration in 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.
messageStoragePolicyobjectOptional. 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. (id: MessageStoragePolicy)
messageTransformsarrayOptional. Transforms to be applied to messages published to the topic. Transforms are applied in the order specified.
satisfiesPzsbooleanOptional. Reserved for future use. This field is set only in responses from the server; it is ignored if it is set in any requests.
schemaSettingsobjectOptional. Settings for validating messages published against a schema. (id: SchemaSettings)
statestringOutput only. An output-only field indicating the state of the topic.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
projects_topics_getselectprojectsId, topicsIdGets the configuration of a topic.
projects_topics_listselectprojectsIdpageSize, pageTokenLists matching topics.
projects_topics_patchupdateprojectsId, topicsIdUpdates an existing topic by updating the fields specified in the update mask. Note that certain properties of a topic are not modifiable.
projects_topics_deletedeleteprojectsId, topicsIdDeletes 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_.
projects_topics_createexecprojectsId, topicsIdCreates the given topic with the given name. See the [resource name rules] (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names).
projects_topics_publishexecprojectsId, topicsIdAdds one or more messages to the topic. Returns NOT_FOUND if the topic does not exist.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
projectsIdstring
topicsIdstring
pageSizeinteger (int32)
pageTokenstring

SELECT examples

Gets the configuration of a topic.

SELECT
name,
ingestionDataSourceSettings,
kmsKeyName,
labels,
messageRetentionDuration,
messageStoragePolicy,
messageTransforms,
satisfiesPzs,
schemaSettings,
state
FROM google.pubsub.topics
WHERE projectsId = '{{ projectsId }}' -- required
AND topicsId = '{{ topicsId }}' -- required;

UPDATE examples

Updates an existing topic by updating the fields specified in the update mask. Note that certain properties of a topic are not modifiable.

UPDATE google.pubsub.topics
SET
data__topic = '{{ topic }}',
data__updateMask = '{{ updateMask }}'
WHERE
projectsId = '{{ projectsId }}' --required
AND topicsId = '{{ topicsId }}' --required
RETURNING
name,
ingestionDataSourceSettings,
kmsKeyName,
labels,
messageRetentionDuration,
messageStoragePolicy,
messageTransforms,
satisfiesPzs,
schemaSettings,
state;

DELETE examples

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

DELETE FROM google.pubsub.topics
WHERE projectsId = '{{ projectsId }}' --required
AND topicsId = '{{ topicsId }}' --required;

Lifecycle Methods

Creates the given topic with the given name. See the [resource name rules] (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names).

EXEC google.pubsub.topics.projects_topics_create 
@projectsId='{{ projectsId }}' --required,
@topicsId='{{ topicsId }}' --required
@@json=
'{
"name": "{{ name }}",
"labels": "{{ labels }}",
"messageStoragePolicy": "{{ messageStoragePolicy }}",
"kmsKeyName": "{{ kmsKeyName }}",
"schemaSettings": "{{ schemaSettings }}",
"satisfiesPzs": {{ satisfiesPzs }},
"messageRetentionDuration": "{{ messageRetentionDuration }}",
"ingestionDataSourceSettings": "{{ ingestionDataSourceSettings }}",
"messageTransforms": "{{ messageTransforms }}"
}';