xref: /aosp_15_r20/external/googleapis/google/cloud/pubsublite/v1/subscriber.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
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//     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
15syntax = "proto3";
16
17package google.cloud.pubsublite.v1;
18
19import "google/api/annotations.proto";
20import "google/api/client.proto";
21import "google/api/field_behavior.proto";
22import "google/cloud/pubsublite/v1/common.proto";
23
24option cc_enable_arenas = true;
25option csharp_namespace = "Google.Cloud.PubSubLite.V1";
26option go_package = "cloud.google.com/go/pubsublite/apiv1/pubsublitepb;pubsublitepb";
27option java_multiple_files = true;
28option java_outer_classname = "SubscriberProto";
29option java_package = "com.google.cloud.pubsublite.proto";
30option php_namespace = "Google\\Cloud\\PubSubLite\\V1";
31option ruby_package = "Google::Cloud::PubSubLite::V1";
32
33// The service that a subscriber client application uses to receive messages
34// from subscriptions.
35service SubscriberService {
36  option (google.api.default_host) = "pubsublite.googleapis.com";
37  option (google.api.oauth_scopes) =
38      "https://www.googleapis.com/auth/cloud-platform";
39
40  // Establishes a stream with the server for receiving messages.
41  rpc Subscribe(stream SubscribeRequest) returns (stream SubscribeResponse) {}
42}
43
44// The service that a subscriber client application uses to determine which
45// partitions it should connect to.
46service PartitionAssignmentService {
47  option (google.api.default_host) = "pubsublite.googleapis.com";
48  option (google.api.oauth_scopes) =
49      "https://www.googleapis.com/auth/cloud-platform";
50
51  // Assign partitions for this client to handle for the specified subscription.
52  //
53  // The client must send an InitialPartitionAssignmentRequest first.
54  // The server will then send at most one unacknowledged PartitionAssignment
55  // outstanding on the stream at a time.
56  // The client should send a PartitionAssignmentAck after updating the
57  // partitions it is connected to to reflect the new assignment.
58  rpc AssignPartitions(stream PartitionAssignmentRequest)
59      returns (stream PartitionAssignment) {}
60}
61
62// The first request that must be sent on a newly-opened stream. The client must
63// wait for the response before sending subsequent requests on the stream.
64message InitialSubscribeRequest {
65  // The subscription from which to receive messages.
66  string subscription = 1;
67
68  // The partition from which to receive messages. Partitions are zero indexed,
69  // so `partition` must be in the range [0, topic.num_partitions).
70  int64 partition = 2;
71
72  // Optional. Initial target location within the message backlog. If not set,
73  // messages will be delivered from the commit cursor for the given
74  // subscription and partition.
75  SeekRequest initial_location = 4 [(google.api.field_behavior) = OPTIONAL];
76}
77
78// Response to an InitialSubscribeRequest.
79message InitialSubscribeResponse {
80  // The cursor from which the subscriber will start receiving messages once
81  // flow control tokens become available.
82  Cursor cursor = 1;
83}
84
85// Request to update the stream's delivery cursor based on the given target.
86// Resets the server available tokens to 0. SeekRequests past head result in
87// stream breakage.
88//
89// SeekRequests may not be sent while another SeekRequest is outstanding (i.e.,
90// has not received a SeekResponse) on the same stream.
91message SeekRequest {
92  // A special target in the partition that takes no other parameters.
93  enum NamedTarget {
94    // Default value. This value is unused.
95    NAMED_TARGET_UNSPECIFIED = 0;
96
97    // A target corresponding to the most recently published message in the
98    // partition.
99    HEAD = 1;
100
101    // A target corresponding to the committed cursor for the given subscription
102    // and topic partition.
103    COMMITTED_CURSOR = 2;
104  }
105
106  // The target to seek to. Must be set.
107  oneof target {
108    // A named target.
109    NamedTarget named_target = 1;
110
111    // A target corresponding to the cursor, pointing to anywhere in the
112    // topic partition.
113    Cursor cursor = 2;
114  }
115}
116
117// Response to a SeekRequest.
118message SeekResponse {
119  // The new delivery cursor for the current stream.
120  Cursor cursor = 1;
121}
122
123// Request to grant tokens to the server, requesting delivery of messages when
124// they become available.
125message FlowControlRequest {
126  // The number of message tokens to grant. Must be greater than or equal to 0.
127  int64 allowed_messages = 1;
128
129  // The number of byte tokens to grant. Must be greater than or equal to 0.
130  int64 allowed_bytes = 2;
131}
132
133// A request sent from the client to the server on a stream.
134message SubscribeRequest {
135  // The type of request this is.
136  oneof request {
137    // Initial request on the stream.
138    InitialSubscribeRequest initial = 1;
139
140    // Request to update the stream's delivery cursor.
141    SeekRequest seek = 2;
142
143    // Request to grant tokens to the server,
144    FlowControlRequest flow_control = 3;
145  }
146}
147
148// Response containing a list of messages. Upon delivering a MessageResponse to
149// the client, the server:
150// *  Updates the stream's delivery cursor to one greater than the cursor of the
151//    last message in the list.
152// *  Subtracts the total number of bytes and messages from the tokens available
153//    to the server.
154message MessageResponse {
155  // Messages from the topic partition.
156  repeated SequencedMessage messages = 1;
157}
158
159// Response to SubscribeRequest.
160message SubscribeResponse {
161  // The type of response this is.
162  oneof response {
163    // Initial response on the stream.
164    InitialSubscribeResponse initial = 1;
165
166    // Response to a Seek operation.
167    SeekResponse seek = 2;
168
169    // Response containing messages from the topic partition.
170    MessageResponse messages = 3;
171  }
172}
173
174// The first request that must be sent on a newly-opened stream. The client must
175// wait for the response before sending subsequent requests on the stream.
176message InitialPartitionAssignmentRequest {
177  // The subscription name. Structured like:
178  // projects/<project number>/locations/<zone name>/subscriptions/<subscription
179  // id>
180  string subscription = 1;
181
182  // An opaque, unique client identifier. This field must be exactly 16 bytes
183  // long and is interpreted as an unsigned 128 bit integer. Other size values
184  // will be rejected and the stream will be failed with a non-retryable error.
185  //
186  // This field is large enough to fit a uuid from standard uuid algorithms like
187  // uuid1 or uuid4, which should be used to generate this number. The same
188  // identifier should be reused following disconnections with retryable stream
189  // errors.
190  bytes client_id = 2;
191}
192
193// PartitionAssignments should not race with acknowledgements. There
194// should be exactly one unacknowledged PartitionAssignment at a time. If not,
195// the client must break the stream.
196message PartitionAssignment {
197  // The list of partition numbers this subscriber is assigned to.
198  repeated int64 partitions = 1;
199}
200
201// Acknowledge receipt and handling of the previous assignment.
202// If not sent within a short period after receiving the assignment,
203// partitions may remain unassigned for a period of time until the
204// client is known to be inactive, after which time the server will break the
205// stream.
206message PartitionAssignmentAck {}
207
208// A request on the PartitionAssignment stream.
209message PartitionAssignmentRequest {
210  // The type of request this is.
211  oneof request {
212    // Initial request on the stream.
213    InitialPartitionAssignmentRequest initial = 1;
214
215    // Acknowledgement of a partition assignment.
216    PartitionAssignmentAck ack = 2;
217  }
218}
219