PublishStream RPC Method

The PublishStream method uses bidirectional streaming. It can send a stream of publish requests while receiving a stream of publish responses from the server. Use PublishStream to achieve a higher publish rate than with Publish.

The first PublishRequest of the stream identifies the topic to publish on. If a subsequent PublishRequest provides topic_name, it must match what was provided in the first PublishRequest. Otherwise, the RPC sends an error with an INVALID_ARGUMENT status.

The server returns a PublishResponse for each PublishRequest when publishing is complete for the batch. A client doesn’t have to wait for a PublishResponse before sending a new PublishRequest. Multiple publish batches can be queued up. This behavior allows for a higher publish rate because a client can asynchronously publish more events while publish operations are still in flight on the server side.

The PublishResponse holds a PublishResult for each event published that indicates success or failure of the publish operation. A successful status means that the event was published and is in the event bus. A failed status means that the event failed to publish.

To retry publishing failed events, use the Publish unary RPC method instead of PublishStream. You can't retry publishing failed events with PublishStream because you can’t correlate a failed publish result with the corresponding event in PublishRequest.

To hold onto the stream, a client must send a valid publish request with one or more events every 70 seconds. Otherwise, the server closes the stream and notifies the client. When the client is notified of the stream closure, it must make a new PublishStream call to resume publishing.

For more information about the fields in PublishRequest and PublishResponse, see the Pub/Sub API proto file.