Skip to main content

Record Google Pub/Sub traffic

The Google Cloud client libraries call Pub/Sub over gRPC, on pubsub.googleapis.com:443 or a regional endpoint, so proxymock records Pub/Sub calls as gRPC calls. Everything in Record gRPC traffic applies. The PHP library falls back to the REST API when its gRPC extension is missing, and those calls are recorded as HTTP.

What the client does​

  • A publisher sends unary Publish calls, each with one or more messages.
  • A subscriber built on a high-level client opens a bidirectional StreamingPull stream, sends its subscription in the first request, and receives messages on the stream. It acknowledges them with separate unary Acknowledge and ModifyAckDeadline calls, or on the stream itself. Some subscribers use unary Pull calls instead.

A subscriber keeps its stream open for as long as it runs and ends it by cancelling it. proxymock records such a stream as an ordered sequence of parts, a long-lived stream, which the mock serves as one stream.

Record against the emulator​

The Pub/Sub emulator speaks plaintext gRPC, so the simplest recording maps a local port to it. Start the emulator, create your topic and subscription, then map a port:

gcloud beta emulators pubsub start --host-port=localhost:8085
proxymock record --map 18085=localhost:8085

Point the client libraries at the mapped port with the variable they read for the emulator:

PUBSUB_EMULATOR_HOST=localhost:18085 ./your-app

Use the app, then stop the recorder with Ctrl-C.

Record against the Pub/Sub service​

The service is reached over TLS, so the client must send its calls through proxymock and trust the proxymock CA. Set the proxy variables your runtime honors, such as grpc_proxy or HTTPS_PROXY, to the recorder's outbound port, and trust ~/.speedscale/certs/tls.crt. The language reference shows both for each runtime. Record with a test project where you can, because the recording holds the messages your app published and received.

What gets recorded​

Each call is one file under a directory named for the host, such as pubsub.googleapis.com. The location is the gRPC method, such as /google.pubsub.v1.Publisher/Publish or /google.pubsub.v1.Subscriber/StreamingPull.

  • Publish keeps the topic and each message's data, attributes and ordering key, and the message IDs Pub/Sub returned.
  • StreamingPull keeps the requests the client sent, starting with the one that names the subscription, and every response the service pushed, each with its messages and ack IDs and the time it arrived.
  • Pull keeps the messages it returned.

proxymock names the fields with the Pub/Sub .proto files it ships with, so the messages read as JSON with their field names. See Name fields with your .proto.

This filter lists every subscriber call, which is also the filter that picks the deliveries to republish when you test a subscriber:

(location CONTAINS "google.pubsub.v1.Subscriber")

In a cluster​

In Kubernetes, the sidecar can decrypt outbound TLS to record Pub/Sub, and the eBPF collector can read plaintext where the application opens the TLS connection. Both capture StreamingPull by default. Look for a StreamingPull call containing messages before you create the snapshot. See Record a subscriber in your cluster for troubleshooting. Java subscribers built on google-cloud-pubsub need a current Java agent image. See gRPC Java and Google Cloud clients.

REST clients are captured as outbound HTTP calls. If you use a push subscription, capture the inbound HTTP deliveries to your handler.

Next​

Loading search...