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/cloud/pubsublite/v1/common.proto"; 22 23option cc_enable_arenas = true; 24option csharp_namespace = "Google.Cloud.PubSubLite.V1"; 25option go_package = "cloud.google.com/go/pubsublite/apiv1/pubsublitepb;pubsublitepb"; 26option java_multiple_files = true; 27option java_outer_classname = "PublisherProto"; 28option java_package = "com.google.cloud.pubsublite.proto"; 29option php_namespace = "Google\\Cloud\\PubSubLite\\V1"; 30option ruby_package = "Google::Cloud::PubSubLite::V1"; 31 32// The service that a publisher client application uses to publish messages to 33// topics. Published messages are retained by the service for the duration of 34// the retention period configured for the respective topic, and are delivered 35// to subscriber clients upon request (via the `SubscriberService`). 36service PublisherService { 37 option (google.api.default_host) = "pubsublite.googleapis.com"; 38 option (google.api.oauth_scopes) = 39 "https://www.googleapis.com/auth/cloud-platform"; 40 41 // Establishes a stream with the server for publishing messages. Once the 42 // stream is initialized, the client publishes messages by sending publish 43 // requests on the stream. The server responds with a PublishResponse for each 44 // PublishRequest sent by the client, in the same order that the requests 45 // were sent. Note that multiple PublishRequests can be in flight 46 // simultaneously, but they will be processed by the server in the order that 47 // they are sent by the client on a given stream. 48 rpc Publish(stream PublishRequest) returns (stream PublishResponse) {} 49} 50 51// The first request that must be sent on a newly-opened stream. 52message InitialPublishRequest { 53 // The topic to which messages will be written. 54 string topic = 1; 55 56 // The partition within the topic to which messages will be written. 57 // Partitions are zero indexed, so `partition` must be in the range [0, 58 // topic.num_partitions). 59 int64 partition = 2; 60 61 // Unique identifier for a publisher client. If set, enables publish 62 // idempotency within a publisher client session. 63 // 64 // The length of this field must be exactly 16 bytes long and should be 65 // populated with a 128 bit uuid, generated by standard uuid algorithms like 66 // uuid1 or uuid4. The same identifier should be reused following 67 // disconnections with retryable stream errors. 68 bytes client_id = 3; 69} 70 71// Response to an InitialPublishRequest. 72message InitialPublishResponse {} 73 74// Request to publish messages to the topic. 75message MessagePublishRequest { 76 // The messages to publish. 77 repeated PubSubMessage messages = 1; 78 79 // The sequence number corresponding to the first message in `messages`. 80 // Messages within a batch are ordered and the sequence numbers of all 81 // subsequent messages in the batch are assumed to be incremental. 82 // 83 // Sequence numbers are assigned at the message level and the first message 84 // published in a publisher client session must have a sequence number of 0. 85 // All messages must have contiguous sequence numbers, which uniquely identify 86 // the messages accepted by the publisher client. Since messages are ordered, 87 // the client only needs to specify the sequence number of the first message 88 // in a published batch. The server deduplicates messages with the same 89 // sequence number from the same publisher `client_id`. 90 int64 first_sequence_number = 2; 91} 92 93// Response to a MessagePublishRequest. 94message MessagePublishResponse { 95 // Cursors for a subrange of published messages. 96 message CursorRange { 97 // The cursor of the message at the start index. The cursors for remaining 98 // messages up to the end index (exclusive) are sequential. 99 Cursor start_cursor = 1; 100 101 // Index of the message in the published batch that corresponds to the 102 // start cursor. Inclusive. 103 int32 start_index = 2; 104 105 // Index of the last message in this range. Exclusive. 106 int32 end_index = 3; 107 } 108 109 // The cursor of the first published message in the batch. The cursors for any 110 // remaining messages in the batch are guaranteed to be sequential. 111 Cursor start_cursor = 1; 112 113 // Cursors for messages published in the batch. There will exist multiple 114 // ranges when cursors are not contiguous within the batch. 115 // 116 // The cursor ranges may not account for all messages in the batch when 117 // publish idempotency is enabled. A missing range indicates that cursors 118 // could not be determined for messages within the range, as they were 119 // deduplicated and the necessary data was not available at publish time. 120 // These messages will have offsets when received by a subscriber. 121 repeated CursorRange cursor_ranges = 2; 122} 123 124// Request sent from the client to the server on a stream. 125message PublishRequest { 126 // The type of request this is. 127 oneof request_type { 128 // Initial request on the stream. 129 InitialPublishRequest initial_request = 1; 130 131 // Request to publish messages. 132 MessagePublishRequest message_publish_request = 2; 133 } 134} 135 136// Response to a PublishRequest. 137message PublishResponse { 138 // The type of response this is. 139 oneof response_type { 140 // Initial response on the stream. 141 InitialPublishResponse initial_response = 1; 142 143 // Response to publishing messages. 144 MessagePublishResponse message_response = 2; 145 } 146} 147