Google Cloud Pub/Sub C++ Client 2.13.0
A C++ Client Library for Google Cloud Pub/Sub
|
Publish messages to the Cloud Pub/Sub service. More...
#include <google/cloud/pubsub/publisher.h>
Public Member Functions | |
Publisher (std::shared_ptr< PublisherConnection > connection) | |
Publisher (Publisher const &)=default | |
Publisher & | operator= (Publisher const &)=default |
Publisher (Publisher &&)=default | |
Publisher & | operator= (Publisher &&)=default |
future< StatusOr< std::string > > | Publish (Message m) |
Publishes a message to this publisher's topic. More... | |
void | Flush () |
Forcibly publishes any batched messages. More... | |
void | ResumePublish (std::string ordering_key) |
Resumes publishing after an error. More... | |
Publisher (std::shared_ptr< PublisherConnection > connection, PublisherOptions const &) | |
Friends | |
bool | operator== (Publisher const &a, Publisher const &b) |
bool | operator!= (Publisher const &a, Publisher const &b) |
Publish messages to the Cloud Pub/Sub service.
This class is used to publish messages to a fixed topic, with a fixed configuration such as credentials, batching, background threads, etc. Applications that publish messages to multiple topics need to create separate instances of this class. Applications wanting to publish events with different batching configuration also need to create separate instances.
Publisher
configured to preserve message ordering will sequence the messages that share a common ordering key (see MessageBuilder::SetOrderingKey()
). Messages will be batched by ordering key, and new batches will wait until the status of the previous batch is known. On an error, all pending and queued messages are discarded, and the publisher rejects any new messages for the ordering key that experienced problems. The application must call Publisher::ResumePublishing()
to to restore publishing.Publisher
objects are relatively cheap to create, copy, and move. However, each Publisher
object must be created with a std::shared_ptr<PublisherConnection>
, which itself is relatively expensive to create. Therefore, connection instances should be shared when possible. See the MakePublisherConnection()
method and the PublisherConnection
interface for more details.Options
from GrpcOptionList
. Applications can create their own pool of background threads by (a) creating their own google::cloud::CompletionQueue, (b) passing this completion queue as a GrpcCompletionQueueOption
, and (c) attaching any number of threads to the completion queue.future<T>
(or future<StatusOr<T>>
) object. Readers are probably familiar with std::future<T>
. Our version adds a .then()
function to attach a callback to the future, which is invoked when the future is satisfied. This function returns a future<U>
where U
is the return value of the attached function. More details in the google::cloud::future documentation.StatusOr<T>
to report errors. When an operation fails to perform its work the returned StatusOr<T>
contains the error details. If the ok()
member function in the StatusOr<T>
returns true
then it contains the expected result. Please consult the google::cloud::StatusOr documentation for more details.
|
inlineexplicit |
|
default |
|
default |
|
inlineexplicit |
Publisher(connection)
and provide any configuration options when initializing the connection
object.
|
inline |
Forcibly publishes any batched messages.
As applications can configure a Publisher
to buffer messages, it is sometimes useful to flush them before any of the normal criteria to send the RPCs is met.
Publish()
.Publishes a message to this publisher's topic.
Note that the message may be batched, depending on the Publisher's configuration. It could be delayed until the batch has enough messages, or enough data, or enough time has elapsed. See the PublisherOptionList
documentation for more details.
|
inline |
Resumes publishing after an error.
If the publisher options have message ordering enabled (see MessageOrderingOption
) all messages for a key that experience failure will be rejected until the application calls this function.
Publish()
request may fail for the same ordering key. The application needs to call this function after each error before it can resume publishing messages with the same ordering key.