Client libraries
Use the official Google Cloud Pub/Sub client libraries as published. Set the API endpoint to your cluster’s TLS endpoint. Credentials stay as they are: Application Default Credentials, Workload Identity or a key file.
lowtide is tested with the official Python, Go, Java and Node.js clients: publish, streaming pull, acks and nacks, and ordering keys. Other official clients use the same gRPC API and endpoint setting.
In the examples, replace lowtide.pubsub.svc:443 with your endpoint from the cluster’s Connect tab. If the cluster uses a private CA, also set GRPC_DEFAULT_SSL_ROOTS_FILE_PATH (Private CA).
Python
Section titled “Python”from google.cloud import pubsub_v1
endpoint = {"api_endpoint": "lowtide.pubsub.svc:443"}publisher = pubsub_v1.PublisherClient(client_options=endpoint)subscriber = pubsub_v1.SubscriberClient(client_options=endpoint)
future = publisher.publish("projects/acme/topics/orders", b"hello", kind="test")print(future.result())import ( "cloud.google.com/go/pubsub" "google.golang.org/api/option")
client, err := pubsub.NewClient(ctx, "acme", option.WithEndpoint("lowtide.pubsub.svc:443"))Publisher publisher = Publisher.newBuilder(TopicName.of("acme", "orders")) .setEndpoint("lowtide.pubsub.svc:443") .build();
Subscriber subscriber = Subscriber.newBuilder(ProjectSubscriptionName.of("acme", "orders-billing"), receiver) .setEndpoint("lowtide.pubsub.svc:443") .build();For admin calls, set the endpoint on the settings builder: TopicAdminSettings.newBuilder().setEndpoint("lowtide.pubsub.svc:443"), and the same for SubscriptionAdminSettings.
Node.js
Section titled “Node.js”const { PubSub } = require('@google-cloud/pubsub');
const pubsub = new PubSub({ apiEndpoint: 'lowtide.pubsub.svc:443' });await pubsub.topic('orders').publishMessage({ data: Buffer.from('hello') });Read the endpoint from configuration
Section titled “Read the endpoint from configuration”Make each service read the Pub/Sub endpoint from its configuration, with Pub/Sub’s own endpoint as the default. Then moving a service to lowtide, or back, is a configuration change and a restart, with no code change.
import osfrom google.cloud import pubsub_v1
options = {"api_endpoint": os.environ["PUBSUB_ENDPOINT"]} if "PUBSUB_ENDPOINT" in os.environ else Nonepublisher = pubsub_v1.PublisherClient(client_options=options)Do this before you migrate. The console’s migration setup checklist shows the same pattern for each language.
What behaves differently
Section titled “What behaves differently”The API is the same. A few behaviours differ from Pub/Sub:
- Redelivery after failover. Like Pub/Sub, lowtide is at-least-once. After a pod restarts or a shard moves, messages delivered since the last recorded acknowledgement position (at most about a second) can arrive again.
- Delivery attempts for dead-letter policies are counted in memory, so a count starts again after a failover.
- Ordering during pod changes. When pods join or leave, some ordering keys move to another pod. Messages for a moved key published just before and just after the move can arrive out of order.
- Delivery by zone. Subscribers in a zone receive the messages published in that zone. A zone with no subscribers is served from the other zone, pod to pod or, with the Lowest cost setting, through Cloud Storage about 1 second later. See Cross-zone delivery.
- Long-lived connections. After a gateway pod restarts, a client that reconnected to the other zone keeps that connection until it reconnects, so its traffic crosses zones until then.
The compatibility reference lists every feature.