Chen Wang | 405392c | 2015-02-03 10:28:39 -0800 | [diff] [blame] | 1 | // This file will be moved to a new location. |
Chen Wang | b532ef8 | 2015-02-02 10:45:17 -0800 | [diff] [blame] | 2 | |
Craig Tiller | ad1fd3a | 2015-02-16 12:23:04 -0800 | [diff] [blame] | 3 | // Copyright 2015, Google Inc. |
| 4 | // All rights reserved. |
Craig Tiller | ce5021b | 2015-02-18 09:25:21 -0800 | [diff] [blame] | 5 | // |
Craig Tiller | ad1fd3a | 2015-02-16 12:23:04 -0800 | [diff] [blame] | 6 | // Redistribution and use in source and binary forms, with or without |
| 7 | // modification, are permitted provided that the following conditions are |
| 8 | // met: |
Craig Tiller | ce5021b | 2015-02-18 09:25:21 -0800 | [diff] [blame] | 9 | // |
Craig Tiller | ad1fd3a | 2015-02-16 12:23:04 -0800 | [diff] [blame] | 10 | // * Redistributions of source code must retain the above copyright |
| 11 | // notice, this list of conditions and the following disclaimer. |
| 12 | // * Redistributions in binary form must reproduce the above |
| 13 | // copyright notice, this list of conditions and the following disclaimer |
| 14 | // in the documentation and/or other materials provided with the |
| 15 | // distribution. |
| 16 | // * Neither the name of Google Inc. nor the names of its |
| 17 | // contributors may be used to endorse or promote products derived from |
| 18 | // this software without specific prior written permission. |
Craig Tiller | ce5021b | 2015-02-18 09:25:21 -0800 | [diff] [blame] | 19 | // |
Craig Tiller | ad1fd3a | 2015-02-16 12:23:04 -0800 | [diff] [blame] | 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | |
Chen Wang | 86af8cf | 2015-01-21 18:05:40 -0800 | [diff] [blame] | 33 | // Specification of the Pubsub API. |
| 34 | |
| 35 | syntax = "proto2"; |
| 36 | |
Chen wang | 8423251 | 2015-02-12 17:29:18 -0800 | [diff] [blame] | 37 | import "examples/pubsub/empty.proto"; |
| 38 | import "examples/pubsub/label.proto"; |
Chen Wang | 86af8cf | 2015-01-21 18:05:40 -0800 | [diff] [blame] | 39 | |
| 40 | package tech.pubsub; |
| 41 | |
| 42 | // ----------------------------------------------------------------------------- |
| 43 | // Overview of the Pubsub API |
| 44 | // ----------------------------------------------------------------------------- |
| 45 | |
| 46 | // This file describes an API for a Pubsub system. This system provides a |
| 47 | // reliable many-to-many communication mechanism between independently written |
| 48 | // publishers and subscribers where the publisher publishes messages to "topics" |
| 49 | // and each subscriber creates a "subscription" and consumes messages from it. |
| 50 | // |
| 51 | // (a) The pubsub system maintains bindings between topics and subscriptions. |
| 52 | // (b) A publisher publishes messages into a topic. |
| 53 | // (c) The pubsub system delivers messages from topics into relevant |
| 54 | // subscriptions. |
| 55 | // (d) A subscriber receives pending messages from its subscription and |
| 56 | // acknowledges or nacks each one to the pubsub system. |
| 57 | // (e) The pubsub system removes acknowledged messages from that subscription. |
| 58 | |
| 59 | // ----------------------------------------------------------------------------- |
| 60 | // Data Model |
| 61 | // ----------------------------------------------------------------------------- |
| 62 | |
| 63 | // The data model consists of the following: |
| 64 | // |
| 65 | // * Topic: A topic is a resource to which messages are published by publishers. |
| 66 | // Topics are named, and the name of the topic is unique within the pubsub |
| 67 | // system. |
| 68 | // |
| 69 | // * Subscription: A subscription records the subscriber's interest in a topic. |
| 70 | // It can optionally include a query to select a subset of interesting |
| 71 | // messages. The pubsub system maintains a logical cursor tracking the |
| 72 | // matching messages which still need to be delivered and acked so that |
| 73 | // they can retried as needed. The set of messages that have not been |
| 74 | // acknowledged is called the subscription backlog. |
| 75 | // |
| 76 | // * Message: A message is a unit of data that flows in the system. It contains |
| 77 | // opaque data from the publisher along with its labels. |
| 78 | // |
| 79 | // * Message Labels (optional): A set of opaque key, value pairs assigned |
| 80 | // by the publisher which the subscriber can use for filtering out messages |
| 81 | // in the topic. For example, a label with key "foo.com/device_type" and |
| 82 | // value "mobile" may be added for messages that are only relevant for a |
| 83 | // mobile subscriber; a subscriber on a phone may decide to create a |
| 84 | // subscription only for messages that have this label. |
| 85 | |
| 86 | // ----------------------------------------------------------------------------- |
| 87 | // Publisher Flow |
| 88 | // ----------------------------------------------------------------------------- |
| 89 | |
| 90 | // A publisher publishes messages to the topic using the Publish request: |
| 91 | // |
| 92 | // PubsubMessage message; |
| 93 | // message.set_data("...."); |
| 94 | // Label label; |
| 95 | // label.set_key("foo.com/key1"); |
| 96 | // label.set_str_value("value1"); |
| 97 | // message.add_label(label); |
| 98 | // PublishRequest request; |
| 99 | // request.set_topic("topicName"); |
| 100 | // request.set_message(message); |
| 101 | // PublisherService.Publish(request); |
| 102 | |
| 103 | // ----------------------------------------------------------------------------- |
| 104 | // Subscriber Flow |
| 105 | // ----------------------------------------------------------------------------- |
| 106 | |
| 107 | // The subscriber part of the API is richer than the publisher part and has a |
| 108 | // number of concepts w.r.t. subscription creation and monitoring: |
| 109 | // |
| 110 | // (1) A subscriber creates a subscription using the CreateSubscription call. |
| 111 | // It may specify an optional "query" to indicate that it wants to receive |
| 112 | // only messages with a certain set of labels using the label query syntax. |
| 113 | // It may also specify an optional truncation policy to indicate when old |
| 114 | // messages from the subcription can be removed. |
| 115 | // |
| 116 | // (2) A subscriber receives messages in one of two ways: via push or pull. |
| 117 | // |
| 118 | // (a) To receive messages via push, the PushConfig field must be specified in |
| 119 | // the Subscription parameter when creating a subscription. The PushConfig |
| 120 | // specifies an endpoint at which the subscriber must expose the |
| 121 | // PushEndpointService. Messages are received via the HandlePubsubEvent |
| 122 | // method. The push subscriber responds to the HandlePubsubEvent method |
| 123 | // with a result code that indicates one of three things: Ack (the message |
| 124 | // has been successfully processed and the Pubsub system may delete it), |
| 125 | // Nack (the message has been rejected, the Pubsub system should resend it |
| 126 | // at a later time), or Push-Back (this is a Nack with the additional |
| 127 | // semantics that the subscriber is overloaded and the pubsub system should |
| 128 | // back off on the rate at which it is invoking HandlePubsubEvent). The |
| 129 | // endpoint may be a load balancer for better scalability. |
| 130 | // |
| 131 | // (b) To receive messages via pull a subscriber calls the Pull method on the |
| 132 | // SubscriberService to get messages from the subscription. For each |
| 133 | // individual message, the subscriber may use the ack_id received in the |
| 134 | // PullResponse to Ack the message, Nack the message, or modify the ack |
| 135 | // deadline with ModifyAckDeadline. See the |
| 136 | // Subscription.ack_deadline_seconds field documentation for details on the |
| 137 | // ack deadline behavior. |
| 138 | // |
| 139 | // Note: Messages may be consumed in parallel by multiple subscribers making |
| 140 | // Pull calls to the same subscription; this will result in the set of |
| 141 | // messages from the subscription being shared and each subscriber |
| 142 | // receiving a subset of the messages. |
| 143 | // |
| 144 | // (4) The subscriber can explicitly truncate the current subscription. |
| 145 | // |
| 146 | // (5) "Truncated" events are delivered when a subscription is |
| 147 | // truncated, whether due to the subscription's truncation policy |
| 148 | // or an explicit request from the subscriber. |
| 149 | // |
| 150 | // Subscription creation: |
| 151 | // |
| 152 | // Subscription subscription; |
| 153 | // subscription.set_topic("topicName"); |
| 154 | // subscription.set_name("subscriptionName"); |
| 155 | // subscription.push_config().set_push_endpoint("machinename:8888"); |
| 156 | // SubscriberService.CreateSubscription(subscription); |
| 157 | // |
| 158 | // Consuming messages via push: |
| 159 | // |
Yang Gao | bbd67c0 | 2015-02-20 13:04:52 -0800 | [diff] [blame^] | 160 | // The port 'machinename:8888' must be bound to a server that implements |
Chen Wang | 86af8cf | 2015-01-21 18:05:40 -0800 | [diff] [blame] | 161 | // the PushEndpointService with the following method: |
| 162 | // |
| 163 | // int HandlePubsubEvent(PubsubEvent event) { |
| 164 | // if (event.subscription().equals("subscriptionName")) { |
| 165 | // if (event.has_message()) { |
| 166 | // Process(event.message().data()); |
| 167 | // } else if (event.truncated()) { |
| 168 | // ProcessTruncatedEvent(); |
| 169 | // } |
| 170 | // } |
| 171 | // return OK; // This return code implies an acknowledgment |
| 172 | // } |
| 173 | // |
| 174 | // Consuming messages via pull: |
| 175 | // |
| 176 | // The subscription must be created without setting the push_config field. |
| 177 | // |
| 178 | // PullRequest pull_request; |
| 179 | // pull_request.set_subscription("subscriptionName"); |
| 180 | // pull_request.set_return_immediately(false); |
| 181 | // while (true) { |
| 182 | // PullResponse pull_response; |
| 183 | // if (SubscriberService.Pull(pull_request, pull_response) == OK) { |
| 184 | // PubsubEvent event = pull_response.pubsub_event(); |
| 185 | // if (event.has_message()) { |
| 186 | // Process(event.message().data()); |
| 187 | // } else if (event.truncated()) { |
| 188 | // ProcessTruncatedEvent(); |
| 189 | // } |
| 190 | // AcknowledgeRequest ack_request; |
| 191 | // ackRequest.set_subscription("subscriptionName"); |
| 192 | // ackRequest.set_ack_id(pull_response.ack_id()); |
| 193 | // SubscriberService.Acknowledge(ack_request); |
| 194 | // } |
| 195 | // } |
| 196 | |
| 197 | // ----------------------------------------------------------------------------- |
| 198 | // Reliability Semantics |
| 199 | // ----------------------------------------------------------------------------- |
| 200 | |
| 201 | // When a subscriber successfully creates a subscription using |
| 202 | // Subscriber.CreateSubscription, it establishes a "subscription point" with |
| 203 | // respect to that subscription - the subscriber is guaranteed to receive any |
| 204 | // message published after this subscription point that matches the |
| 205 | // subscription's query. Note that messages published before the Subscription |
| 206 | // point may or may not be delivered. |
| 207 | // |
| 208 | // If the system truncates the subscription according to the specified |
| 209 | // truncation policy, the system delivers a subscription status event with the |
| 210 | // "truncated" field set to true. We refer to such events as "truncation |
| 211 | // events". A truncation event: |
| 212 | // |
| 213 | // * Informs the subscriber that part of the subscription messages have been |
| 214 | // discarded. The subscriber may want to recover from the message loss, e.g., |
| 215 | // by resyncing its state with its backend. |
| 216 | // * Establishes a new subscription point, i.e., the subscriber is guaranteed to |
| 217 | // receive all changes published after the trunction event is received (or |
| 218 | // until another truncation event is received). |
| 219 | // |
| 220 | // Note that messages are not delivered in any particular order by the pubsub |
| 221 | // system. Furthermore, the system guarantees at-least-once delivery |
| 222 | // of each message or truncation events until acked. |
| 223 | |
| 224 | // ----------------------------------------------------------------------------- |
| 225 | // Deletion |
| 226 | // ----------------------------------------------------------------------------- |
| 227 | |
| 228 | // Both topics and subscriptions may be deleted. Deletion of a topic implies |
| 229 | // deletion of all attached subscriptions. |
| 230 | // |
| 231 | // When a subscription is deleted directly by calling DeleteSubscription, all |
| 232 | // messages are immediately dropped. If it is a pull subscriber, future pull |
| 233 | // requests will return NOT_FOUND. |
| 234 | // |
| 235 | // When a topic is deleted all corresponding subscriptions are immediately |
| 236 | // deleted, and subscribers experience the same behavior as directly deleting |
| 237 | // the subscription. |
| 238 | |
| 239 | // ----------------------------------------------------------------------------- |
| 240 | // The Publisher service and its protos. |
| 241 | // ----------------------------------------------------------------------------- |
| 242 | |
| 243 | // The service that an application uses to manipulate topics, and to send |
| 244 | // messages to a topic. |
| 245 | service PublisherService { |
| 246 | |
| 247 | // Creates the given topic with the given name. |
| 248 | rpc CreateTopic(Topic) returns (Topic) { |
| 249 | } |
| 250 | |
| 251 | // Adds a message to the topic. Returns NOT_FOUND if the topic does not |
| 252 | // exist. |
Chen Wang | 86af8cf | 2015-01-21 18:05:40 -0800 | [diff] [blame] | 253 | rpc Publish(PublishRequest) returns (proto2.Empty) { |
| 254 | } |
| 255 | |
| 256 | // Adds one or more messages to the topic. Returns NOT_FOUND if the topic does |
| 257 | // not exist. |
| 258 | rpc PublishBatch(PublishBatchRequest) returns (PublishBatchResponse) { |
| 259 | } |
| 260 | |
| 261 | // Gets the configuration of a topic. Since the topic only has the name |
| 262 | // attribute, this method is only useful to check the existence of a topic. |
| 263 | // If other attributes are added in the future, they will be returned here. |
| 264 | rpc GetTopic(GetTopicRequest) returns (Topic) { |
| 265 | } |
| 266 | |
| 267 | // Lists matching topics. |
| 268 | rpc ListTopics(ListTopicsRequest) returns (ListTopicsResponse) { |
| 269 | } |
| 270 | |
| 271 | // Deletes the topic with the given name. All subscriptions to this topic |
| 272 | // are also deleted. Returns NOT_FOUND if the topic does not exist. |
| 273 | // After a topic is deleted, a new topic may be created with the same name. |
| 274 | rpc DeleteTopic(DeleteTopicRequest) returns (proto2.Empty) { |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // A topic resource. |
| 279 | message Topic { |
| 280 | // Name of the topic. |
| 281 | optional string name = 1; |
| 282 | } |
| 283 | |
| 284 | // A message data and its labels. |
| 285 | message PubsubMessage { |
| 286 | // The message payload. |
| 287 | optional bytes data = 1; |
| 288 | |
| 289 | // Optional list of labels for this message. Keys in this collection must |
| 290 | // be unique. |
Chen Wang | 86af8cf | 2015-01-21 18:05:40 -0800 | [diff] [blame] | 291 | repeated tech.label.Label label = 2; |
| 292 | |
| 293 | // ID of this message assigned by the server at publication time. Guaranteed |
| 294 | // to be unique within the topic. This value may be read by a subscriber |
| 295 | // that receives a PubsubMessage via a Pull call or a push delivery. It must |
| 296 | // not be populated by a publisher in a Publish call. |
| 297 | optional string message_id = 3; |
| 298 | } |
| 299 | |
| 300 | // Request for the GetTopic method. |
| 301 | message GetTopicRequest { |
| 302 | // The name of the topic to get. |
| 303 | optional string topic = 1; |
| 304 | } |
| 305 | |
| 306 | // Request for the Publish method. |
| 307 | message PublishRequest { |
| 308 | // The message in the request will be published on this topic. |
| 309 | optional string topic = 1; |
| 310 | |
| 311 | // The message to publish. |
| 312 | optional PubsubMessage message = 2; |
| 313 | } |
| 314 | |
| 315 | // Request for the PublishBatch method. |
| 316 | message PublishBatchRequest { |
| 317 | // The messages in the request will be published on this topic. |
| 318 | optional string topic = 1; |
| 319 | |
| 320 | // The messages to publish. |
| 321 | repeated PubsubMessage messages = 2; |
| 322 | } |
| 323 | |
| 324 | // Response for the PublishBatch method. |
| 325 | message PublishBatchResponse { |
| 326 | // The server-assigned ID of each published message, in the same order as |
| 327 | // the messages in the request. IDs are guaranteed to be unique within |
| 328 | // the topic. |
| 329 | repeated string message_ids = 1; |
| 330 | } |
| 331 | |
| 332 | // Request for the ListTopics method. |
| 333 | message ListTopicsRequest { |
| 334 | // A valid label query expression. |
| 335 | // (-- Which labels are required or supported is implementation-specific. --) |
| 336 | optional string query = 1; |
| 337 | |
| 338 | // Maximum number of topics to return. |
| 339 | // (-- If not specified or <= 0, the implementation will select a reasonable |
| 340 | // value. --) |
| 341 | optional int32 max_results = 2; |
| 342 | |
| 343 | // The value obtained in the last <code>ListTopicsResponse</code> |
| 344 | // for continuation. |
| 345 | optional string page_token = 3; |
| 346 | |
| 347 | } |
| 348 | |
| 349 | // Response for the ListTopics method. |
| 350 | message ListTopicsResponse { |
| 351 | // The resulting topics. |
| 352 | repeated Topic topic = 1; |
| 353 | |
| 354 | // If not empty, indicates that there are more topics that match the request, |
| 355 | // and this value should be passed to the next <code>ListTopicsRequest</code> |
| 356 | // to continue. |
| 357 | optional string next_page_token = 2; |
| 358 | } |
| 359 | |
| 360 | // Request for the Delete method. |
| 361 | message DeleteTopicRequest { |
| 362 | // Name of the topic to delete. |
| 363 | optional string topic = 1; |
| 364 | } |
| 365 | |
| 366 | // ----------------------------------------------------------------------------- |
| 367 | // The Subscriber service and its protos. |
| 368 | // ----------------------------------------------------------------------------- |
| 369 | |
| 370 | // The service that an application uses to manipulate subscriptions and to |
| 371 | // consume messages from a subscription via the pull method. |
| 372 | service SubscriberService { |
| 373 | |
| 374 | // Creates a subscription on a given topic for a given subscriber. |
| 375 | // If the subscription already exists, returns ALREADY_EXISTS. |
| 376 | // If the corresponding topic doesn't exist, returns NOT_FOUND. |
| 377 | // |
| 378 | // If the name is not provided in the request, the server will assign a random |
| 379 | // name for this subscription on the same project as the topic. |
| 380 | rpc CreateSubscription(Subscription) returns (Subscription) { |
| 381 | } |
| 382 | |
| 383 | // Gets the configuration details of a subscription. |
| 384 | rpc GetSubscription(GetSubscriptionRequest) returns (Subscription) { |
| 385 | } |
| 386 | |
| 387 | // Lists matching subscriptions. |
| 388 | rpc ListSubscriptions(ListSubscriptionsRequest) |
| 389 | returns (ListSubscriptionsResponse) { |
| 390 | } |
| 391 | |
| 392 | // Deletes an existing subscription. All pending messages in the subscription |
| 393 | // are immediately dropped. Calls to Pull after deletion will return |
| 394 | // NOT_FOUND. |
| 395 | rpc DeleteSubscription(DeleteSubscriptionRequest) returns (proto2.Empty) { |
| 396 | } |
| 397 | |
| 398 | // Removes all the pending messages in the subscription and releases the |
| 399 | // storage associated with them. Results in a truncation event to be sent to |
| 400 | // the subscriber. Messages added after this call returns are stored in the |
| 401 | // subscription as before. |
| 402 | rpc TruncateSubscription(TruncateSubscriptionRequest) returns (proto2.Empty) { |
| 403 | } |
| 404 | |
| 405 | // |
| 406 | // Push subscriber calls. |
| 407 | // |
| 408 | |
| 409 | // Modifies the <code>PushConfig</code> for a specified subscription. |
| 410 | // This method can be used to suspend the flow of messages to an endpoint |
| 411 | // by clearing the <code>PushConfig</code> field in the request. Messages |
| 412 | // will be accumulated for delivery even if no push configuration is |
| 413 | // defined or while the configuration is modified. |
| 414 | rpc ModifyPushConfig(ModifyPushConfigRequest) returns (proto2.Empty) { |
| 415 | } |
| 416 | |
| 417 | // |
| 418 | // Pull Subscriber calls |
| 419 | // |
| 420 | |
| 421 | // Pulls a single message from the server. |
| 422 | // If return_immediately is true, and no messages are available in the |
| 423 | // subscription, this method returns FAILED_PRECONDITION. The system is free |
| 424 | // to return an UNAVAILABLE error if no messages are available in a |
| 425 | // reasonable amount of time (to reduce system load). |
| 426 | rpc Pull(PullRequest) returns (PullResponse) { |
| 427 | } |
| 428 | |
| 429 | // Pulls messages from the server. Returns an empty list if there are no |
| 430 | // messages available in the backlog. The system is free to return UNAVAILABLE |
| 431 | // if there are too many pull requests outstanding for the given subscription. |
| 432 | rpc PullBatch(PullBatchRequest) returns (PullBatchResponse) { |
| 433 | } |
| 434 | |
| 435 | // Modifies the Ack deadline for a message received from a pull request. |
| 436 | rpc ModifyAckDeadline(ModifyAckDeadlineRequest) returns (proto2.Empty) { |
| 437 | } |
| 438 | |
| 439 | // Acknowledges a particular received message: the Pub/Sub system can remove |
| 440 | // the given message from the subscription. Acknowledging a message whose |
| 441 | // Ack deadline has expired may succeed, but the message could have been |
| 442 | // already redelivered. Acknowledging a message more than once will not |
| 443 | // result in an error. This is only used for messages received via pull. |
| 444 | rpc Acknowledge(AcknowledgeRequest) returns (proto2.Empty) { |
| 445 | } |
| 446 | |
| 447 | // Refuses processing a particular received message. The system will |
| 448 | // redeliver this message to some consumer of the subscription at some |
| 449 | // future time. This is only used for messages received via pull. |
| 450 | rpc Nack(NackRequest) returns (proto2.Empty) { |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | // A subscription resource. |
| 455 | message Subscription { |
| 456 | // Name of the subscription. |
| 457 | optional string name = 1; |
| 458 | |
| 459 | // The name of the topic from which this subscription is receiving messages. |
| 460 | optional string topic = 2; |
| 461 | |
| 462 | // If <code>query</code> is non-empty, only messages on the subscriber's |
| 463 | // topic whose labels match the query will be returned. Otherwise all |
| 464 | // messages on the topic will be returned. |
Yang Gao | bbd67c0 | 2015-02-20 13:04:52 -0800 | [diff] [blame^] | 465 | // (-- The query syntax is described in label_query.proto --) |
Chen Wang | 86af8cf | 2015-01-21 18:05:40 -0800 | [diff] [blame] | 466 | optional string query = 3; |
| 467 | |
| 468 | // The subscriber may specify requirements for truncating unacknowledged |
| 469 | // subscription entries. The system will honor the |
| 470 | // <code>CreateSubscription</code> request only if it can meet these |
| 471 | // requirements. If this field is not specified, messages are never truncated |
| 472 | // by the system. |
| 473 | optional TruncationPolicy truncation_policy = 4; |
| 474 | |
| 475 | // Specifies which messages can be truncated by the system. |
| 476 | message TruncationPolicy { |
| 477 | oneof policy { |
| 478 | // If <code>max_bytes</code> is specified, the system is allowed to drop |
| 479 | // old messages to keep the combined size of stored messages under |
| 480 | // <code>max_bytes</code>. This is a hint; the system may keep more than |
| 481 | // this many bytes, but will make a best effort to keep the size from |
| 482 | // growing much beyond this parameter. |
| 483 | int64 max_bytes = 1; |
| 484 | |
| 485 | // If <code>max_age_seconds</code> is specified, the system is allowed to |
| 486 | // drop messages that have been stored for at least this many seconds. |
| 487 | // This is a hint; the system may keep these messages, but will make a |
| 488 | // best effort to remove them when their maximum age is reached. |
| 489 | int64 max_age_seconds = 2; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | // If push delivery is used with this subscription, this field is |
| 494 | // used to configure it. |
| 495 | optional PushConfig push_config = 5; |
| 496 | |
| 497 | // For either push or pull delivery, the value is the maximum time after a |
| 498 | // subscriber receives a message before the subscriber should acknowledge or |
| 499 | // Nack the message. If the Ack deadline for a message passes without an |
| 500 | // Ack or a Nack, the Pub/Sub system will eventually redeliver the message. |
| 501 | // If a subscriber acknowledges after the deadline, the Pub/Sub system may |
| 502 | // accept the Ack, but it is possible that the message has been already |
| 503 | // delivered again. Multiple Acks to the message are allowed and will |
| 504 | // succeed. |
| 505 | // |
| 506 | // For push delivery, this value is used to set the request timeout for |
| 507 | // the call to the push endpoint. |
| 508 | // |
| 509 | // For pull delivery, this value is used as the initial value for the Ack |
| 510 | // deadline. It may be overridden for a specific pull request (message) with |
| 511 | // <code>ModifyAckDeadline</code>. |
| 512 | // While a message is outstanding (i.e. it has been delivered to a pull |
| 513 | // subscriber and the subscriber has not yet Acked or Nacked), the Pub/Sub |
| 514 | // system will not deliver that message to another pull subscriber |
| 515 | // (on a best-effort basis). |
| 516 | optional int32 ack_deadline_seconds = 6; |
| 517 | |
| 518 | // If this parameter is set to n, the system is allowed to (but not required |
| 519 | // to) delete the subscription when at least n seconds have elapsed since the |
| 520 | // client presence was detected. (Presence is detected through any |
| 521 | // interaction using the subscription ID, including Pull(), Get(), or |
| 522 | // acknowledging a message.) |
| 523 | // |
| 524 | // If this parameter is not set, the subscription will stay live until |
| 525 | // explicitly deleted. |
| 526 | // |
| 527 | // Clients can detect such garbage collection when a Get call or a Pull call |
| 528 | // (for pull subscribers only) returns NOT_FOUND. |
| 529 | optional int64 garbage_collect_seconds = 7; |
| 530 | } |
| 531 | |
| 532 | // Configuration for a push delivery endpoint. |
| 533 | message PushConfig { |
| 534 | // A URL locating the endpoint to which messages should be pushed. |
| 535 | // For example, a Webhook endpoint might use "https://example.com/push". |
| 536 | // (-- An Android application might use "gcm:<REGID>", where <REGID> is a |
| 537 | // GCM registration id allocated for pushing messages to the application. --) |
| 538 | optional string push_endpoint = 1; |
| 539 | } |
| 540 | |
| 541 | // An event indicating a received message or truncation event. |
| 542 | message PubsubEvent { |
| 543 | // The subscription that received the event. |
| 544 | optional string subscription = 1; |
| 545 | |
| 546 | oneof type { |
| 547 | // A received message. |
| 548 | PubsubMessage message = 2; |
| 549 | |
| 550 | // Indicates that this subscription has been truncated. |
| 551 | bool truncated = 3; |
| 552 | |
| 553 | // Indicates that this subscription has been deleted. (Note that pull |
| 554 | // subscribers will always receive NOT_FOUND in response in their pull |
| 555 | // request on the subscription, rather than seeing this boolean.) |
| 556 | bool deleted = 4; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | // Request for the GetSubscription method. |
| 561 | message GetSubscriptionRequest { |
| 562 | // The name of the subscription to get. |
| 563 | optional string subscription = 1; |
| 564 | } |
| 565 | |
| 566 | // Request for the ListSubscriptions method. |
| 567 | message ListSubscriptionsRequest { |
| 568 | // A valid label query expression. |
| 569 | // (-- Which labels are required or supported is implementation-specific. |
| 570 | // TODO(eschapira): This method must support to query by topic. We must |
| 571 | // define the key URI for the "topic" label. --) |
| 572 | optional string query = 1; |
| 573 | |
| 574 | // Maximum number of subscriptions to return. |
| 575 | // (-- If not specified or <= 0, the implementation will select a reasonable |
| 576 | // value. --) |
| 577 | optional int32 max_results = 3; |
| 578 | |
| 579 | // The value obtained in the last <code>ListSubscriptionsResponse</code> |
| 580 | // for continuation. |
| 581 | optional string page_token = 4; |
| 582 | } |
| 583 | |
| 584 | // Response for the ListSubscriptions method. |
| 585 | message ListSubscriptionsResponse { |
| 586 | // The subscriptions that match the request. |
| 587 | repeated Subscription subscription = 1; |
| 588 | |
| 589 | // If not empty, indicates that there are more subscriptions that match the |
| 590 | // request and this value should be passed to the next |
| 591 | // <code>ListSubscriptionsRequest</code> to continue. |
| 592 | optional string next_page_token = 2; |
| 593 | } |
| 594 | |
| 595 | // Request for the TruncateSubscription method. |
| 596 | message TruncateSubscriptionRequest { |
| 597 | // The subscription that is being truncated. |
| 598 | optional string subscription = 1; |
| 599 | } |
| 600 | |
| 601 | // Request for the DeleteSubscription method. |
| 602 | message DeleteSubscriptionRequest { |
| 603 | // The subscription to delete. |
| 604 | optional string subscription = 1; |
| 605 | } |
| 606 | |
| 607 | // Request for the ModifyPushConfig method. |
| 608 | message ModifyPushConfigRequest { |
| 609 | // The name of the subscription. |
| 610 | optional string subscription = 1; |
| 611 | |
| 612 | // An empty <code>push_config</code> indicates that the Pub/Sub system should |
| 613 | // pause pushing messages from the given subscription. |
| 614 | optional PushConfig push_config = 2; |
| 615 | } |
| 616 | |
| 617 | // ----------------------------------------------------------------------------- |
| 618 | // The protos used by a pull subscriber. |
| 619 | // ----------------------------------------------------------------------------- |
| 620 | |
| 621 | // Request for the Pull method. |
| 622 | message PullRequest { |
| 623 | // The subscription from which a message should be pulled. |
| 624 | optional string subscription = 1; |
| 625 | |
| 626 | // If this is specified as true the system will respond immediately even if |
| 627 | // it is not able to return a message in the Pull response. Otherwise the |
| 628 | // system is allowed to wait until at least one message is available rather |
| 629 | // than returning FAILED_PRECONDITION. The client may cancel the request if |
| 630 | // it does not wish to wait any longer for the response. |
| 631 | optional bool return_immediately = 2; |
| 632 | } |
| 633 | |
| 634 | // Either a <code>PubsubMessage</code> or a truncation event. One of these two |
| 635 | // must be populated. |
| 636 | message PullResponse { |
| 637 | // This ID must be used to acknowledge the received event or message. |
| 638 | optional string ack_id = 1; |
| 639 | |
| 640 | // A pubsub message or truncation event. |
| 641 | optional PubsubEvent pubsub_event = 2; |
| 642 | } |
| 643 | |
| 644 | // Request for the PullBatch method. |
| 645 | message PullBatchRequest { |
| 646 | // The subscription from which messages should be pulled. |
| 647 | optional string subscription = 1; |
| 648 | |
| 649 | // If this is specified as true the system will respond immediately even if |
| 650 | // it is not able to return a message in the Pull response. Otherwise the |
| 651 | // system is allowed to wait until at least one message is available rather |
| 652 | // than returning no messages. The client may cancel the request if it does |
| 653 | // not wish to wait any longer for the response. |
| 654 | optional bool return_immediately = 2; |
| 655 | |
| 656 | // The maximum number of PubsubEvents returned for this request. The Pub/Sub |
| 657 | // system may return fewer than the number of events specified. |
| 658 | optional int32 max_events = 3; |
| 659 | } |
| 660 | |
| 661 | // Response for the PullBatch method. |
| 662 | message PullBatchResponse { |
| 663 | |
| 664 | // Received Pub/Sub messages or status events. The Pub/Sub system will return |
| 665 | // zero messages if there are no more messages available in the backlog. The |
| 666 | // Pub/Sub system may return fewer than the max_events requested even if |
| 667 | // there are more messages available in the backlog. |
| 668 | repeated PullResponse pull_responses = 2; |
| 669 | } |
| 670 | |
| 671 | // Request for the ModifyAckDeadline method. |
| 672 | message ModifyAckDeadlineRequest { |
| 673 | // The name of the subscription from which messages are being pulled. |
| 674 | optional string subscription = 1; |
| 675 | |
| 676 | // The acknowledgment ID. |
| 677 | optional string ack_id = 2; |
| 678 | |
| 679 | // The new Ack deadline. Must be >= 0. |
| 680 | optional int32 ack_deadline_seconds = 3; |
| 681 | } |
| 682 | |
| 683 | // Request for the Acknowledge method. |
| 684 | message AcknowledgeRequest { |
| 685 | // The subscription whose message is being acknowledged. |
| 686 | optional string subscription = 1; |
| 687 | |
| 688 | // The acknowledgment ID for the message being acknowledged. This was |
| 689 | // returned by the Pub/Sub system in the Pull response. |
| 690 | repeated string ack_id = 2; |
| 691 | } |
| 692 | |
| 693 | // Request for the Nack method. |
| 694 | message NackRequest { |
| 695 | // The subscription whose message is being Nacked. |
| 696 | optional string subscription = 1; |
| 697 | |
| 698 | // The acknowledgment ID for the message being refused. This was returned by |
| 699 | // the Pub/Sub system in the Pull response. |
| 700 | repeated string ack_id = 2; |
| 701 | } |
| 702 | |
| 703 | // ----------------------------------------------------------------------------- |
| 704 | // The service and protos used by a push subscriber. |
| 705 | // ----------------------------------------------------------------------------- |
| 706 | |
| 707 | // The service that a subscriber uses to handle messages sent via push |
| 708 | // delivery. |
| 709 | // This service is not currently exported for HTTP clients. |
| 710 | // TODO(eschapira): Explain HTTP subscribers. |
| 711 | service PushEndpointService { |
| 712 | // Sends a <code>PubsubMessage</code> or a subscription status event to a |
| 713 | // push endpoint. |
| 714 | // The push endpoint responds with an empty message and a code from |
| 715 | // util/task/codes.proto. The following codes have a particular meaning to the |
| 716 | // Pub/Sub system: |
| 717 | // OK - This is interpreted by Pub/Sub as Ack. |
| 718 | // ABORTED - This is intepreted by Pub/Sub as a Nack, without implying |
| 719 | // pushback for congestion control. The Pub/Sub system will |
| 720 | // retry this message at a later time. |
| 721 | // UNAVAILABLE - This is intepreted by Pub/Sub as a Nack, with the additional |
| 722 | // semantics of push-back. The Pub/Sub system will use an AIMD |
| 723 | // congestion control algorithm to backoff the rate of sending |
| 724 | // messages from this subscription. |
| 725 | // Any other code, or a failure to respond, will be interpreted in the same |
| 726 | // way as ABORTED; i.e. the system will retry the message at a later time to |
| 727 | // ensure reliable delivery. |
| 728 | rpc HandlePubsubEvent(PubsubEvent) returns (proto2.Empty); |
| 729 | } |