Class PublisherOptions (2.14.0)

Configuration options for a Publisher.

These are largely used to control the batching configuration for a publisher. By default a publishers flushes a batch as soon as any of these conditions are met:

  • 10ms after the first message is put in the batch,
  • when the batch contains 100 messages or more,
  • when the batch contains 1MiB of data or more.

Applications developers should consult the Cloud Pub/Sub pricing page when selecting a batching configuration.

Example
  namespace pubsub = ::google::cloud::pubsub;
  using ::google::cloud::future;
  using ::google::cloud::Options;
  using ::google::cloud::StatusOr;
  [](std::string project_id, std::string topic_id) {
    auto topic = pubsub::Topic(std::move(project_id), std::move(topic_id));
    // By default, the publisher will flush a batch after 10ms, after it
    // contains more than 100 message, or after it contains more than 1MiB of
    // data, whichever comes first. This changes those defaults.
    auto publisher = pubsub::Publisher(pubsub::MakePublisherConnection(
        std::move(topic),
        Options{}
            .set<pubsub::MaxHoldTimeOption>(std::chrono::milliseconds(20))
            .set<pubsub::MaxBatchBytesOption>(4 * 1024 * 1024L)
            .set<pubsub::MaxBatchMessagesOption>(200)));

    std::vector<future<void>> ids;
    for (char const* data : {"1", "2", "3", "go!"}) {
      ids.push_back(
          publisher.Publish(pubsub::MessageBuilder().SetData(data).Build())
              .then([data](future<StatusOr<std::string>> f) {
                auto s = f.get();
                if (!s) return;
                std::cout << "Sent '" << data << "' (" << *s << ")\n";
              }));
    }
    publisher.Flush();
    // Block until they are actually sent.
    for (auto& id : ids) id.get();
  }

Constructors

PublisherOptions()

PublisherOptions(Options)

Initialize the publisher options.

Expected options are any of the types in the PublisherOptionList

Parameter
Name Description
opts Options

configuration options

Functions

maximum_hold_time() const

Publisher batch control

Returns
Type Description
std::chrono::microseconds

set_maximum_hold_time(std::chrono::duration< Rep, Period >)

Sets the maximum hold time for the messages.

Parameters
Name Description
v std::chrono::duration< Rep, Period >
typename Rep
typename Period
Returns
Type Description
PublisherOptions &

maximum_batch_message_count() const

Publisher batch control

Returns
Type Description
std::size_t

set_maximum_batch_message_count(std::size_t)

Set the maximum number of messages in a batch.

Parameter
Name Description
v std::size_t
Returns
Type Description
PublisherOptions &

maximum_batch_bytes() const

Publisher batch control

Returns
Type Description
std::size_t

set_maximum_batch_bytes(std::size_t)

Set the maximum size for the messages in a batch.

Parameter
Name Description
v std::size_t
Returns
Type Description
PublisherOptions &

message_ordering() const

Return true if message ordering is enabled.

Returns
Type Description
bool

enable_message_ordering()

Enable message ordering.

See Also

the documentation for the Publisher class for details.

Returns
Type Description
PublisherOptions &

disable_message_ordering()

Disable message ordering.

See Also

the documentation for the Publisher class for details.

Returns
Type Description
PublisherOptions &

set_maximum_pending_bytes(std::size_t)

Flow control based on pending bytes.

Parameter
Name Description
v std::size_t
Returns
Type Description
PublisherOptions &

set_maximum_pending_messages(std::size_t)

Flow control based on pending messages.

Parameter
Name Description
v std::size_t
Returns
Type Description
PublisherOptions &

maximum_pending_bytes() const

Publisher flow control.

Returns
Type Description
std::size_t

maximum_pending_messages() const

Publisher flow control.

Returns
Type Description
std::size_t

full_publisher_ignored() const

The current action for a full publisher.

Returns
Type Description
bool

full_publisher_rejects() const

The current action for a full publisher.

Returns
Type Description
bool

full_publisher_blocks() const

The current action for a full publisher.

Returns
Type Description
bool

set_full_publisher_ignored()

Ignore full publishers, continue as usual.

Returns
Type Description
PublisherOptions &

set_full_publisher_rejects()

Configure the publisher to reject new messages when full.

Returns
Type Description
PublisherOptions &

set_full_publisher_blocks()

Configure the publisher to block the caller when full.

Returns
Type Description
PublisherOptions &