google-cloud-pubsub 2.30.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/cloud/pubsub/__init__.py +31 -0
- google/cloud/pubsub_v1/__init__.py +35 -0
- google/cloud/pubsub_v1/exceptions.py +20 -0
- google/cloud/pubsub_v1/futures.py +56 -0
- google/cloud/pubsub_v1/open_telemetry/__init__.py +13 -0
- google/cloud/pubsub_v1/open_telemetry/context_propagation.py +55 -0
- google/cloud/pubsub_v1/open_telemetry/publish_message_wrapper.py +142 -0
- google/cloud/pubsub_v1/open_telemetry/subscribe_opentelemetry.py +280 -0
- google/cloud/pubsub_v1/proto/pubsub.proto +1344 -0
- google/cloud/pubsub_v1/proto/schema.proto +286 -0
- google/cloud/pubsub_v1/publisher/__init__.py +20 -0
- google/cloud/pubsub_v1/publisher/_batch/__init__.py +0 -0
- google/cloud/pubsub_v1/publisher/_batch/base.py +174 -0
- google/cloud/pubsub_v1/publisher/_batch/thread.py +492 -0
- google/cloud/pubsub_v1/publisher/_sequencer/__init__.py +0 -0
- google/cloud/pubsub_v1/publisher/_sequencer/base.py +82 -0
- google/cloud/pubsub_v1/publisher/_sequencer/ordered_sequencer.py +340 -0
- google/cloud/pubsub_v1/publisher/_sequencer/unordered_sequencer.py +167 -0
- google/cloud/pubsub_v1/publisher/client.py +614 -0
- google/cloud/pubsub_v1/publisher/exceptions.py +51 -0
- google/cloud/pubsub_v1/publisher/flow_controller.py +313 -0
- google/cloud/pubsub_v1/publisher/futures.py +83 -0
- google/cloud/pubsub_v1/subscriber/__init__.py +20 -0
- google/cloud/pubsub_v1/subscriber/_protocol/__init__.py +0 -0
- google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py +658 -0
- google/cloud/pubsub_v1/subscriber/_protocol/heartbeater.py +77 -0
- google/cloud/pubsub_v1/subscriber/_protocol/helper_threads.py +122 -0
- google/cloud/pubsub_v1/subscriber/_protocol/histogram.py +159 -0
- google/cloud/pubsub_v1/subscriber/_protocol/leaser.py +292 -0
- google/cloud/pubsub_v1/subscriber/_protocol/messages_on_hold.py +182 -0
- google/cloud/pubsub_v1/subscriber/_protocol/requests.py +62 -0
- google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py +1309 -0
- google/cloud/pubsub_v1/subscriber/client.py +323 -0
- google/cloud/pubsub_v1/subscriber/exceptions.py +44 -0
- google/cloud/pubsub_v1/subscriber/futures.py +125 -0
- google/cloud/pubsub_v1/subscriber/message.py +532 -0
- google/cloud/pubsub_v1/subscriber/scheduler.py +170 -0
- google/cloud/pubsub_v1/types.py +336 -0
- google/pubsub/__init__.py +174 -0
- google/pubsub/gapic_version.py +16 -0
- google/pubsub/py.typed +2 -0
- google/pubsub_v1/__init__.py +172 -0
- google/pubsub_v1/gapic_metadata.json +591 -0
- google/pubsub_v1/gapic_version.py +16 -0
- google/pubsub_v1/py.typed +2 -0
- google/pubsub_v1/services/__init__.py +15 -0
- google/pubsub_v1/services/publisher/__init__.py +22 -0
- google/pubsub_v1/services/publisher/async_client.py +1670 -0
- google/pubsub_v1/services/publisher/client.py +2136 -0
- google/pubsub_v1/services/publisher/pagers.py +508 -0
- google/pubsub_v1/services/publisher/transports/__init__.py +38 -0
- google/pubsub_v1/services/publisher/transports/base.py +427 -0
- google/pubsub_v1/services/publisher/transports/grpc.py +667 -0
- google/pubsub_v1/services/publisher/transports/grpc_asyncio.py +847 -0
- google/pubsub_v1/services/publisher/transports/rest.py +2511 -0
- google/pubsub_v1/services/publisher/transports/rest_base.py +678 -0
- google/pubsub_v1/services/schema_service/__init__.py +22 -0
- google/pubsub_v1/services/schema_service/async_client.py +1783 -0
- google/pubsub_v1/services/schema_service/client.py +2197 -0
- google/pubsub_v1/services/schema_service/pagers.py +352 -0
- google/pubsub_v1/services/schema_service/transports/__init__.py +38 -0
- google/pubsub_v1/services/schema_service/transports/base.py +439 -0
- google/pubsub_v1/services/schema_service/transports/grpc.py +676 -0
- google/pubsub_v1/services/schema_service/transports/grpc_asyncio.py +858 -0
- google/pubsub_v1/services/schema_service/transports/rest.py +2718 -0
- google/pubsub_v1/services/schema_service/transports/rest_base.py +746 -0
- google/pubsub_v1/services/subscriber/__init__.py +22 -0
- google/pubsub_v1/services/subscriber/async_client.py +2643 -0
- google/pubsub_v1/services/subscriber/client.py +3094 -0
- google/pubsub_v1/services/subscriber/pagers.py +352 -0
- google/pubsub_v1/services/subscriber/transports/__init__.py +38 -0
- google/pubsub_v1/services/subscriber/transports/base.py +589 -0
- google/pubsub_v1/services/subscriber/transports/grpc.py +921 -0
- google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py +1207 -0
- google/pubsub_v1/services/subscriber/transports/rest.py +3561 -0
- google/pubsub_v1/services/subscriber/transports/rest_base.py +1024 -0
- google/pubsub_v1/types/__init__.py +169 -0
- google/pubsub_v1/types/pubsub.py +3478 -0
- google/pubsub_v1/types/schema.py +511 -0
- google_cloud_pubsub-2.30.0.data/scripts/fixup_pubsub_v1_keywords.py +210 -0
- google_cloud_pubsub-2.30.0.dist-info/METADATA +283 -0
- google_cloud_pubsub-2.30.0.dist-info/RECORD +85 -0
- google_cloud_pubsub-2.30.0.dist-info/WHEEL +5 -0
- google_cloud_pubsub-2.30.0.dist-info/licenses/LICENSE +202 -0
- google_cloud_pubsub-2.30.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// Copyright 2020 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
|
+
// http://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
|
+
syntax = "proto3";
|
|
16
|
+
|
|
17
|
+
package google.pubsub.v1;
|
|
18
|
+
|
|
19
|
+
import "google/api/annotations.proto";
|
|
20
|
+
import "google/api/client.proto";
|
|
21
|
+
import "google/api/field_behavior.proto";
|
|
22
|
+
import "google/api/resource.proto";
|
|
23
|
+
import "google/protobuf/empty.proto";
|
|
24
|
+
|
|
25
|
+
option cc_enable_arenas = true;
|
|
26
|
+
option csharp_namespace = "Google.Cloud.PubSub.V1";
|
|
27
|
+
option go_package = "google.golang.org/genproto/googleapis/pubsub/v1;pubsub";
|
|
28
|
+
option java_multiple_files = true;
|
|
29
|
+
option java_outer_classname = "SchemaProto";
|
|
30
|
+
option java_package = "com.google.pubsub.v1";
|
|
31
|
+
option php_namespace = "Google\\Cloud\\PubSub\\V1";
|
|
32
|
+
option ruby_package = "Google::Cloud::PubSub::V1";
|
|
33
|
+
|
|
34
|
+
// Service for doing schema-related operations.
|
|
35
|
+
service SchemaService {
|
|
36
|
+
option (google.api.default_host) = "pubsub.googleapis.com";
|
|
37
|
+
option (google.api.oauth_scopes) =
|
|
38
|
+
"https://www.googleapis.com/auth/cloud-platform,"
|
|
39
|
+
"https://www.googleapis.com/auth/pubsub";
|
|
40
|
+
|
|
41
|
+
// Creates a schema.
|
|
42
|
+
rpc CreateSchema(CreateSchemaRequest) returns (Schema) {
|
|
43
|
+
option (google.api.http) = {
|
|
44
|
+
post: "/v1/{parent=projects/*}/schemas"
|
|
45
|
+
body: "schema"
|
|
46
|
+
};
|
|
47
|
+
option (google.api.method_signature) = "parent,schema,schema_id";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Gets a schema.
|
|
51
|
+
rpc GetSchema(GetSchemaRequest) returns (Schema) {
|
|
52
|
+
option (google.api.http) = {
|
|
53
|
+
get: "/v1/{name=projects/*/schemas/*}"
|
|
54
|
+
};
|
|
55
|
+
option (google.api.method_signature) = "name";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Lists schemas in a project.
|
|
59
|
+
rpc ListSchemas(ListSchemasRequest) returns (ListSchemasResponse) {
|
|
60
|
+
option (google.api.http) = {
|
|
61
|
+
get: "/v1/{parent=projects/*}/schemas"
|
|
62
|
+
};
|
|
63
|
+
option (google.api.method_signature) = "parent";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Deletes a schema.
|
|
67
|
+
rpc DeleteSchema(DeleteSchemaRequest) returns (google.protobuf.Empty) {
|
|
68
|
+
option (google.api.http) = {
|
|
69
|
+
delete: "/v1/{name=projects/*/schemas/*}"
|
|
70
|
+
};
|
|
71
|
+
option (google.api.method_signature) = "name";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Validates a schema.
|
|
75
|
+
rpc ValidateSchema(ValidateSchemaRequest) returns (ValidateSchemaResponse) {
|
|
76
|
+
option (google.api.http) = {
|
|
77
|
+
post: "/v1/{parent=projects/*}/schemas:validate"
|
|
78
|
+
body: "*"
|
|
79
|
+
};
|
|
80
|
+
option (google.api.method_signature) = "parent,schema";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Validates a message against a schema.
|
|
84
|
+
rpc ValidateMessage(ValidateMessageRequest)
|
|
85
|
+
returns (ValidateMessageResponse) {
|
|
86
|
+
option (google.api.http) = {
|
|
87
|
+
post: "/v1/{parent=projects/*}/schemas:validateMessage"
|
|
88
|
+
body: "*"
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// A schema resource.
|
|
94
|
+
message Schema {
|
|
95
|
+
option (google.api.resource) = {
|
|
96
|
+
type: "pubsub.googleapis.com/Schema"
|
|
97
|
+
pattern: "projects/{project}/schemas/{schema}"
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Possible schema definition types.
|
|
101
|
+
enum Type {
|
|
102
|
+
// Default value. This value is unused.
|
|
103
|
+
TYPE_UNSPECIFIED = 0;
|
|
104
|
+
|
|
105
|
+
// A Protocol Buffer schema definition.
|
|
106
|
+
PROTOCOL_BUFFER = 1;
|
|
107
|
+
|
|
108
|
+
// An Avro schema definition.
|
|
109
|
+
AVRO = 2;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Required. Name of the schema.
|
|
113
|
+
// Format is `projects/{project}/schemas/{schema}`.
|
|
114
|
+
string name = 1 [(google.api.field_behavior) = REQUIRED];
|
|
115
|
+
|
|
116
|
+
// The type of the schema definition.
|
|
117
|
+
Type type = 2;
|
|
118
|
+
|
|
119
|
+
// The definition of the schema. This should contain a string representing
|
|
120
|
+
// the full definition of the schema that is a valid schema definition of
|
|
121
|
+
// the type specified in `type`.
|
|
122
|
+
string definition = 3;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Request for the CreateSchema method.
|
|
126
|
+
message CreateSchemaRequest {
|
|
127
|
+
// Required. The name of the project in which to create the schema.
|
|
128
|
+
// Format is `projects/{project-id}`.
|
|
129
|
+
string parent = 1 [
|
|
130
|
+
(google.api.field_behavior) = REQUIRED,
|
|
131
|
+
(google.api.resource_reference) = {
|
|
132
|
+
child_type: "pubsub.googleapis.com/Schema"
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
// Required. The schema object to create.
|
|
137
|
+
//
|
|
138
|
+
// This schema's `name` parameter is ignored. The schema object returned
|
|
139
|
+
// by CreateSchema will have a `name` made using the given `parent` and
|
|
140
|
+
// `schema_id`.
|
|
141
|
+
Schema schema = 2 [(google.api.field_behavior) = REQUIRED];
|
|
142
|
+
|
|
143
|
+
// The ID to use for the schema, which will become the final component of
|
|
144
|
+
// the schema's resource name.
|
|
145
|
+
//
|
|
146
|
+
// See https://cloud.google.com/pubsub/docs/admin#resource_names for resource
|
|
147
|
+
// name constraints.
|
|
148
|
+
string schema_id = 3;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// View of Schema object fields to be returned by GetSchema and ListSchemas.
|
|
152
|
+
enum SchemaView {
|
|
153
|
+
// The default / unset value.
|
|
154
|
+
// The API will default to the BASIC view.
|
|
155
|
+
SCHEMA_VIEW_UNSPECIFIED = 0;
|
|
156
|
+
|
|
157
|
+
// Include the name and type of the schema, but not the definition.
|
|
158
|
+
BASIC = 1;
|
|
159
|
+
|
|
160
|
+
// Include all Schema object fields.
|
|
161
|
+
FULL = 2;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Request for the GetSchema method.
|
|
165
|
+
message GetSchemaRequest {
|
|
166
|
+
// Required. The name of the schema to get.
|
|
167
|
+
// Format is `projects/{project}/schemas/{schema}`.
|
|
168
|
+
string name = 1 [
|
|
169
|
+
(google.api.field_behavior) = REQUIRED,
|
|
170
|
+
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
// The set of fields to return in the response. If not set, returns a Schema
|
|
174
|
+
// with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all
|
|
175
|
+
// fields.
|
|
176
|
+
SchemaView view = 2;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Request for the `ListSchemas` method.
|
|
180
|
+
message ListSchemasRequest {
|
|
181
|
+
// Required. The name of the project in which to list schemas.
|
|
182
|
+
// Format is `projects/{project-id}`.
|
|
183
|
+
string parent = 1 [
|
|
184
|
+
(google.api.field_behavior) = REQUIRED,
|
|
185
|
+
(google.api.resource_reference) = {
|
|
186
|
+
type: "cloudresourcemanager.googleapis.com/Project"
|
|
187
|
+
}
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
// The set of Schema fields to return in the response. If not set, returns
|
|
191
|
+
// Schemas with `name` and `type`, but not `definition`. Set to `FULL` to
|
|
192
|
+
// retrieve all fields.
|
|
193
|
+
SchemaView view = 2;
|
|
194
|
+
|
|
195
|
+
// Maximum number of schemas to return.
|
|
196
|
+
int32 page_size = 3;
|
|
197
|
+
|
|
198
|
+
// The value returned by the last `ListSchemasResponse`; indicates that
|
|
199
|
+
// this is a continuation of a prior `ListSchemas` call, and that the
|
|
200
|
+
// system should return the next page of data.
|
|
201
|
+
string page_token = 4;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Response for the `ListSchemas` method.
|
|
205
|
+
message ListSchemasResponse {
|
|
206
|
+
// The resulting schemas.
|
|
207
|
+
repeated Schema schemas = 1;
|
|
208
|
+
|
|
209
|
+
// If not empty, indicates that there may be more schemas that match the
|
|
210
|
+
// request; this value should be passed in a new `ListSchemasRequest`.
|
|
211
|
+
string next_page_token = 2;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Request for the `DeleteSchema` method.
|
|
215
|
+
message DeleteSchemaRequest {
|
|
216
|
+
// Required. Name of the schema to delete.
|
|
217
|
+
// Format is `projects/{project}/schemas/{schema}`.
|
|
218
|
+
string name = 1 [
|
|
219
|
+
(google.api.field_behavior) = REQUIRED,
|
|
220
|
+
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
|
|
221
|
+
];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Request for the `ValidateSchema` method.
|
|
225
|
+
message ValidateSchemaRequest {
|
|
226
|
+
// Required. The name of the project in which to validate schemas.
|
|
227
|
+
// Format is `projects/{project-id}`.
|
|
228
|
+
string parent = 1 [
|
|
229
|
+
(google.api.field_behavior) = REQUIRED,
|
|
230
|
+
(google.api.resource_reference) = {
|
|
231
|
+
type: "cloudresourcemanager.googleapis.com/Project"
|
|
232
|
+
}
|
|
233
|
+
];
|
|
234
|
+
|
|
235
|
+
// Required. The schema object to validate.
|
|
236
|
+
Schema schema = 2 [(google.api.field_behavior) = REQUIRED];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Response for the `ValidateSchema` method.
|
|
240
|
+
message ValidateSchemaResponse {}
|
|
241
|
+
|
|
242
|
+
// Request for the `ValidateMessage` method.
|
|
243
|
+
message ValidateMessageRequest {
|
|
244
|
+
// Required. The name of the project in which to validate schemas.
|
|
245
|
+
// Format is `projects/{project-id}`.
|
|
246
|
+
string parent = 1 [
|
|
247
|
+
(google.api.field_behavior) = REQUIRED,
|
|
248
|
+
(google.api.resource_reference) = {
|
|
249
|
+
type: "cloudresourcemanager.googleapis.com/Project"
|
|
250
|
+
}
|
|
251
|
+
];
|
|
252
|
+
|
|
253
|
+
oneof schema_spec {
|
|
254
|
+
// Name of the schema against which to validate.
|
|
255
|
+
//
|
|
256
|
+
// Format is `projects/{project}/schemas/{schema}`.
|
|
257
|
+
string name = 2 [
|
|
258
|
+
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
// Ad-hoc schema against which to validate
|
|
262
|
+
Schema schema = 3;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Message to validate against the provided `schema_spec`.
|
|
266
|
+
bytes message = 4;
|
|
267
|
+
|
|
268
|
+
// The encoding expected for messages
|
|
269
|
+
Encoding encoding = 5;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Response for the `ValidateMessage` method.
|
|
273
|
+
message ValidateMessageResponse {}
|
|
274
|
+
|
|
275
|
+
// Possible encoding types for messages.
|
|
276
|
+
enum Encoding {
|
|
277
|
+
// Unspecified
|
|
278
|
+
ENCODING_UNSPECIFIED = 0;
|
|
279
|
+
|
|
280
|
+
// JSON encoding
|
|
281
|
+
JSON = 1;
|
|
282
|
+
|
|
283
|
+
// Binary encoding, as defined by the schema type. For some schema types,
|
|
284
|
+
// binary encoding may not be available.
|
|
285
|
+
BINARY = 2;
|
|
286
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Copyright 2017, Google LLC All rights reserved.
|
|
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
|
+
# http://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
|
+
from __future__ import absolute_import
|
|
16
|
+
|
|
17
|
+
from google.cloud.pubsub_v1.publisher.client import Client
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
__all__ = ("Client",)
|
|
File without changes
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Copyright 2017, Google LLC All rights reserved.
|
|
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
|
+
# http://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
|
+
from __future__ import absolute_import
|
|
16
|
+
|
|
17
|
+
import abc
|
|
18
|
+
import enum
|
|
19
|
+
import typing
|
|
20
|
+
from typing import Optional, Sequence
|
|
21
|
+
|
|
22
|
+
from google.cloud.pubsub_v1.open_telemetry.publish_message_wrapper import (
|
|
23
|
+
PublishMessageWrapper,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if typing.TYPE_CHECKING: # pragma: NO COVER
|
|
28
|
+
from google.cloud import pubsub_v1
|
|
29
|
+
from google.cloud.pubsub_v1 import types
|
|
30
|
+
from google.pubsub_v1 import types as gapic_types
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Batch(metaclass=abc.ABCMeta):
|
|
34
|
+
"""The base batching class for Pub/Sub publishing.
|
|
35
|
+
|
|
36
|
+
Although the :class:`~.pubsub_v1.publisher.batch.thread.Batch` class, based
|
|
37
|
+
on :class:`threading.Thread`, is fine for most cases, advanced
|
|
38
|
+
users may need to implement something based on a different concurrency
|
|
39
|
+
model.
|
|
40
|
+
|
|
41
|
+
This class defines the interface for the Batch implementation;
|
|
42
|
+
subclasses may be passed as the ``batch_class`` argument to
|
|
43
|
+
:class:`~.pubsub_v1.client.PublisherClient`.
|
|
44
|
+
|
|
45
|
+
The batching behavior works like this: When the
|
|
46
|
+
:class:`~.pubsub_v1.publisher.client.Client` is asked to publish a new
|
|
47
|
+
message, it requires a batch. The client will see if there is an
|
|
48
|
+
already-opened batch for the given topic; if there is, then the message
|
|
49
|
+
is sent to that batch. If there is not, then a new batch is created
|
|
50
|
+
and the message put there.
|
|
51
|
+
|
|
52
|
+
When a new batch is created, it automatically starts a timer counting
|
|
53
|
+
down to the maximum latency before the batch should commit.
|
|
54
|
+
Essentially, if enough time passes, the batch automatically commits
|
|
55
|
+
regardless of how much is in it. However, if either the message count or
|
|
56
|
+
size thresholds are encountered first, then the batch will commit early.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __len__(self):
|
|
60
|
+
"""Return the number of messages currently in the batch."""
|
|
61
|
+
return len(self.message_wrappers)
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
@abc.abstractmethod
|
|
65
|
+
def make_lock(): # pragma: NO COVER
|
|
66
|
+
"""Return a lock in the chosen concurrency model.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
ContextManager: A newly created lock.
|
|
70
|
+
"""
|
|
71
|
+
raise NotImplementedError
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
@abc.abstractmethod
|
|
75
|
+
def message_wrappers(self) -> Sequence[PublishMessageWrapper]: # pragma: NO COVER
|
|
76
|
+
"""Return the messages currently in the batch.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
The messages currently in the batch.
|
|
80
|
+
"""
|
|
81
|
+
raise NotImplementedError
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
@abc.abstractmethod
|
|
85
|
+
def size(self) -> int: # pragma: NO COVER
|
|
86
|
+
"""Return the total size of all of the messages currently in the batch.
|
|
87
|
+
|
|
88
|
+
The size includes any overhead of the actual ``PublishRequest`` that is
|
|
89
|
+
sent to the backend.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
int: The total size of all of the messages currently
|
|
93
|
+
in the batch (including the request overhead), in bytes.
|
|
94
|
+
"""
|
|
95
|
+
raise NotImplementedError
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
@abc.abstractmethod
|
|
99
|
+
def settings(self) -> "types.BatchSettings": # pragma: NO COVER
|
|
100
|
+
"""Return the batch settings.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
The batch settings. These are considered immutable once the batch has
|
|
104
|
+
been opened.
|
|
105
|
+
"""
|
|
106
|
+
raise NotImplementedError
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
@abc.abstractmethod
|
|
110
|
+
def status(self) -> "BatchStatus": # pragma: NO COVER
|
|
111
|
+
"""Return the status of this batch.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
The status of this batch. All statuses are human-readable, all-lowercase
|
|
115
|
+
strings. The ones represented in the :class:`BaseBatch.Status` enum are
|
|
116
|
+
special, but other statuses are permitted.
|
|
117
|
+
"""
|
|
118
|
+
raise NotImplementedError
|
|
119
|
+
|
|
120
|
+
def cancel(
|
|
121
|
+
self, cancellation_reason: "BatchCancellationReason"
|
|
122
|
+
) -> None: # pragma: NO COVER
|
|
123
|
+
"""Complete pending futures with an exception.
|
|
124
|
+
|
|
125
|
+
This method must be called before publishing starts (ie: while the
|
|
126
|
+
batch is still accepting messages.)
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
cancellation_reason:
|
|
130
|
+
The reason why this batch has been cancelled.
|
|
131
|
+
"""
|
|
132
|
+
raise NotImplementedError
|
|
133
|
+
|
|
134
|
+
@abc.abstractmethod
|
|
135
|
+
def publish(
|
|
136
|
+
self, message: "gapic_types.PubsubMessage"
|
|
137
|
+
) -> Optional["pubsub_v1.publisher.futures.Future"]: # pragma: NO COVER
|
|
138
|
+
"""Publish a single message.
|
|
139
|
+
|
|
140
|
+
Add the given message to this object; this will cause it to be
|
|
141
|
+
published once the batch either has enough messages or a sufficient
|
|
142
|
+
period of time has elapsed.
|
|
143
|
+
|
|
144
|
+
This method is called by :meth:`~.PublisherClient.publish`.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
message: The Pub/Sub message.
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
An object conforming to the :class:`concurrent.futures.Future` interface.
|
|
151
|
+
If :data:`None` is returned, that signals that the batch cannot
|
|
152
|
+
accept a message.
|
|
153
|
+
"""
|
|
154
|
+
raise NotImplementedError
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class BatchStatus(str, enum.Enum):
|
|
158
|
+
"""An enum-like class representing valid statuses for a batch."""
|
|
159
|
+
|
|
160
|
+
ACCEPTING_MESSAGES = "accepting messages"
|
|
161
|
+
STARTING = "starting"
|
|
162
|
+
IN_PROGRESS = "in progress"
|
|
163
|
+
ERROR = "error"
|
|
164
|
+
SUCCESS = "success"
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class BatchCancellationReason(str, enum.Enum):
|
|
168
|
+
"""An enum-like class representing reasons why a batch was cancelled."""
|
|
169
|
+
|
|
170
|
+
PRIOR_ORDERED_MESSAGE_FAILED = (
|
|
171
|
+
"Batch cancelled because prior ordered message for the same key has "
|
|
172
|
+
"failed. This batch has been cancelled to avoid out-of-order publish."
|
|
173
|
+
)
|
|
174
|
+
CLIENT_STOPPED = "Batch cancelled because the publisher client has been stopped."
|