Cloud PubSub Client - Class BatchPublisher (2.4.0)

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
Name Description
topicName string

The topic name.

options array

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

↳ enableCompression bool

Flag to enable compression of messages before publishing. Set the flag to true to enable compression. Defaults to false. Messsages are compressed if their total size >= compressionBytesThreshold, whose default value has been experimentally derived after performance evaluations.

↳ compressionBytesThreshold int

The threshold byte size above which messages are compressed. This only takes effect if enableCompression is set to true. Defaults to 240.

publish

Send messages to a batch queue.

Example:

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

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

Returns
Type Description
void

publishDeferred

See also:

Parameters
Name Description
messages array[]

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

options array

[optional] Configuration Options

Returns
Type Description
array A list of message IDs.

Constants

ID_TEMPLATE

Value: 'pubsub-topic-%s'