Cloud PubSub Client - Class BatchPublisher (1.43.2)

Reference documentation and code samples for the Cloud PubSub Client class BatchPublisher.

Publishes messages to Google Cloud Pub\Sub with background batching.

Example:

use Google\Cloud\PubSub\PubSubClient;

$pubsub = new PubSubClient();
$batchPublisher = $pubsub->topic('my_topic')
    ->batchPublisher();

$batchPublisher->publish([
    'data' => 'An important message.'
]);

Namespace

Google \ Cloud \ PubSub

Methods

__construct

Parameters
NameDescription
topicName string

The topic name.

options array

[optional] Please see Google\Cloud\PubSub\Google\Cloud\PubSub\Topic::batchPublisher() for configuration details.

publish

Send messages to a batch queue.

Example:

$batchPublisher->publish([
    'data' => 'An important message.'
]);
Parameter
NameDescription
message Google\Cloud\PubSub\Message|array

An instance of Google\Cloud\PubSub\Google\Cloud\PubSub\Message, or an array in the correct Message Format.

Returns
TypeDescription
void

publishDeferred

Publish a set of deferred messages, sorted into multiple calls by ordering key.

Intended for internal use only by the batch publisher.

Parameters
NameDescription
messages array[]

A list of messages. Each message must be in the correct Message Format.

options array

[optional] Configuration Options

Returns
TypeDescription
arrayA list of message IDs.

Constants

ID_TEMPLATE

Value: 'pubsub-topic-%s'