This page contains code samples for Pub/Sub Lite. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.
Create a Lite subscription that writes messages to a Pub/Sub topic
Create a Lite subscription that writes messages to a Pub/Sub topic
View in documentation
View in documentation
View in documentation
Create Lite topic
Create a single-partition Lite topic and configure its retention period, per partition storage, and publishing throughput scaling factor.
View in documentation
View in documentation
View in documentation
View in documentation
View in documentation
Get Lite subscription
Print name, topic path, and delivery config of a Lite subscription.
View in documentation
View in documentation
View in documentation
View in documentation
View in documentation
View in documentation
Publish
Publish messages to a single-partition Lite topic and resolve the publish futures asynchronously.
Publish messages from Apache Kafka
Publish messages to a Pub/Sub Lite topic using a shim for the Kafka Producer API
View in documentation
View in documentation
View in documentation
Publish with ordering keys
Publish messages with an ordering key. Ordering keys are hashed to map to a partition. Messages of the same ordering key get published to the same partition. If the partition is filled up, oldest messages get written over.
View in documentation
Read from Pub/Sub Lite from Spark (streaming)
Read messages from a Pub/Sub Lite subscription from a Spark cluster in the streaming mode.
View in documentation
Receive messages in Apache Kafka
Receive messages from a Pub/Sub Lite subscription using a shim for the Kafka Consumer API
View in documentation
Seek to a location in a Pub/Sub Lite subscription
Seek to a location in a Pub/Sub Lite subscription to start receiving messages from that location.
View in documentation
Stream Pub/Sub Lite to Cloud Storage using Dataflow
This sample shows how to create an Apache Beam streaming pipeline that reads messages from Pub/Sub Lite, group the messages using a fixed-sized windowing function, and writes them to Cloud Storage.
View in documentation
Subscribe
Use a multi-partition and flow-controlled subscriber (a collection of subscribers) to subscribe to a multiple-partition topic and process messages asynchronously in callbacks.
View in documentation
View in documentation
Update Lite topic
Update the retention period, the scaling factor (throughput capacity), and per partition bytes (storage capacity) of a Lite topic.
View in documentation
Write to Pub/Sub Lite from Spark (streaming)
Write messages to a Pub/Sub Lite topic from a Spark cluster in the streaming mode.
View in documentation