createTopic method
Creates a topic with the given topic
. The topic
can either be the
simple name of the topic or it may be the fully quantified name in the
projects/{project}/topics/{topic}
format.
If set, the kmsKeyName
represents 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/*
.
Implementation
Future<Topic> createTopic({
Map<String, String>? labels,
MessageStoragePolicy? messageStoragePolicy,
String? kmsKeyName,
int retries = 5,
SchemaSettings? schemaSettings,
Duration? messageRetentionDuration,
required String topic,
}) async {
assert(_initialized);
_logger.fine('[createTopic]: start -- [$topic]');
try {
return await _execute(
executor: () async {
final request = Topic(
labels: labels,
messageStoragePolicy: messageStoragePolicy,
kmsKeyName: kmsKeyName,
schemaSettings: schemaSettings,
messageRetentionDuration: messageRetentionDuration == null
? null
: '${messageRetentionDuration.inSeconds}s',
);
final result = await _pubsubApi.projects.topics.create(
request,
topic.startsWith('projects/')
? topic
: 'projects/$_projectId/topics/$topic',
);
return result;
},
retries: retries,
);
} finally {
_logger.fine('[createTopic]: complete -- [$topic]');
}
}