publish method
Adds one or more messages to the topic
. Returns NOT_FOUND
if the topic
does not exist.
The topic
can be just the simple name or it can be the fully quantified
name in the format: projects/{project}/topics/{topic}
.
Implementation
Future<PublishResponse> publish({
required Iterable<PubsubMessage> messages,
int retries = 5,
required String topic,
}) async {
assert(_initialized);
try {
_logger.fine('[publish]: start -- [$topic]');
} catch (e) {
// no-op; in the event that log events are sent via PubSub, this can
// trigger errors trying to log this information out. So... ignore that
// error as log errors should never be allowed to create issues.
}
try {
return await _execute(
executor: () async {
final result = await _pubsubApi.projects.topics.publish(
PublishRequest(
messages: messages.toList(),
),
topic.startsWith('projects/')
? topic
: 'projects/$_projectId/topics/$topic',
);
_logger.finest('[publish]: result -- [${result.messageIds}]');
return result;
},
retries: retries,
);
} finally {
try {
_logger.fine('[publish]: complete -- [$topic]');
} catch (e) {
// no-op; in the event that log events are sent via PubSub, this can
// trigger errors trying to log this information out. So... ignore that
// error as log errors should never be allowed to create issues.
}
}
}