How to publish batched messages to a pubsub topic with retrying request

321 Views Asked by At

I've read all this doc : https://cloud.google.com/pubsub/docs/publisher there are 3 examples:

  1. Publishing to topic
  2. Publishing with batch mode
  3. Publishing with retrying requests

I want to combine example 2 and 3 into single so publishing with batch mode works with retrying requests. How can I do this?

1

There are 1 best solutions below

0
On BEST ANSWER

The object pubsub_v1.PublisherClient accepts both parameters as input for the construction.

By including the two optional parameters batch_settings and client_config you can configure batch mode with retrying requests.

from google.cloud import pubsub_v1

publisher_client = pubsub_v1.PublisherClient(
    # Optional Batch param
    batch_settings = pubsub_v1.types.BatchSettings(
        max_bytes=1024,  # One kilobyte
        max_latency=1,   # One second
    ),

    # Optional Retrying param
    client_config = {
        "interfaces": {
            "google.pubsub.v1.Publisher": {
                "retry_params": {
                    "messaging": {
                        'total_timeout_millis': 650000,  # default: 600000
                    }
                }
            }
        }
    },

    # Optional
    client_options = {
        "api_endpoint": REGIONAL_ENDPOINT
    }
)