Google Cloud Pub/Sub C++ Client 2.13.0
A C++ Client Library for Google Cloud Pub/Sub
Loading...
Searching...
No Matches
blocking_publisher_connection.h
1// Copyright 2022 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_BLOCKING_PUBLISHER_CONNECTION_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_BLOCKING_PUBLISHER_CONNECTION_H
17
18#include "google/cloud/pubsub/backoff_policy.h"
19#include "google/cloud/pubsub/connection_options.h"
20#include "google/cloud/pubsub/internal/publisher_stub.h"
21#include "google/cloud/pubsub/message.h"
22#include "google/cloud/pubsub/publisher_options.h"
23#include "google/cloud/pubsub/retry_policy.h"
24#include "google/cloud/pubsub/topic.h"
25#include "google/cloud/pubsub/version.h"
26#include "google/cloud/future.h"
27#include "google/cloud/internal/non_constructible.h"
28#include "google/cloud/status_or.h"
29#include <initializer_list>
30#include <string>
31#include <vector>
32
33namespace google {
34namespace cloud {
35namespace pubsub {
36GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
37
38/**
39 * A connection to the Cloud Pub/Sub service to publish events.
40 *
41 * This interface defines pure-virtual methods for each of the user-facing
42 * overload sets in `BlockingPublisher`. That is, all of `BlockingPublisher`'s
43 * overloads will forward to the one pure-virtual method declared in this
44 * interface. This allows users to inject custom behavior (e.g., with a Google
45 * Mock object) in a `BlockingPublisher` object for use in their own tests.
46 *
47 * To create a concrete instance that connects you to the real Cloud Pub/Sub
48 * service, see `MakeBlockingPublisherConnection()`.
49 *
50 * @par The *Params nested classes
51 * Applications may define classes derived from `PublisherConnection`, for
52 * example, because they want to mock the class. To avoid breaking all such
53 * derived classes when we change the number or type of the arguments to the
54 * member functions we define lightweight structures to pass the arguments.
55 */
57 public:
58 virtual ~BlockingPublisherConnection() = 0;
59
60 /// Wrap the arguments for `Publish()`
61 struct PublishParams {
64 };
65
66 /// Defines the interface for `BlockingPublisher::Publish()`
67 virtual StatusOr<std::string> Publish(PublishParams p);
68
69 /// Returns the options configured at initialization time.
70 virtual Options options() { return Options{}; }
71};
72
73/**
74 * Creates a new `BlockingPublisherConnection` object to work with
75 * `BlockingPublisher`.
76 *
77 * The `BlockingPublisherConnection` class is provided for applications wanting
78 * to mock the `BlockingPublisher` behavior in their tests. It is not intended
79 * for direct use.
80 *
81 * @par Performance
82 * Creating a new `BlockingPublisherConnection` is relatively expensive. This
83 * typically initiates connections to the service, and therefore these objects
84 * should be shared and reused when possible. Note that gRPC reuses existing OS
85 * resources (sockets) whenever possible, so applications may experience better
86 * performance on the second (and subsequent) calls to this function with the
87 * same `Options` from `GrpcOptionList` and `CommonOptionList`. However, this
88 * behavior is not guaranteed and applications should not rely on it.
89 *
90 * @see `BlockingPublisherConnection`
91 *
92 * @param opts The options to use for this call. Expected options are any of
93 * the types in the following option lists.
94 * - `google::cloud::CommonOptionList`
95 * - `google::cloud::GrpcOptionList`
96 * - `google::cloud::pubsub::PolicyOptionList`
97 * - `google::cloud::pubsub::PublisherOptionList`
98 */
100 Options opts = {});
101
102GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
103} // namespace pubsub
104} // namespace cloud
105} // namespace google
106
107#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_BLOCKING_PUBLISHER_CONNECTION_H
A connection to the Cloud Pub/Sub service to publish events.
Definition: blocking_publisher_connection.h:56
virtual StatusOr< std::string > Publish(PublishParams p)
Defines the interface for BlockingPublisher::Publish()
virtual Options options()
Returns the options configured at initialization time.
Definition: blocking_publisher_connection.h:70
The C++ representation for a Cloud Pub/Sub messages.
Definition: message.h:78
Objects of this class identify a Cloud Pub/Sub topic.
Definition: topic.h:37
Contains all the Cloud Pub/Sub C++ client types and functions.
Definition: ack_handler.h:25
std::shared_ptr< BlockingPublisherConnection > MakeBlockingPublisherConnection(Options opts={})
Creates a new BlockingPublisherConnection object to work with BlockingPublisher.
The namespace Google Cloud Platform C++ client libraries.
Wrap the arguments for Publish()
Definition: blocking_publisher_connection.h:61
Topic topic
Definition: blocking_publisher_connection.h:62
Message message
Definition: blocking_publisher_connection.h:63