subscriber.proto 7.8 KB

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