0

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?

robsiemb
  • 6,157
  • 7
  • 32
  • 46
Rehan
  • 408
  • 1
  • 6
  • 17

1 Answers1

1

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
    }
)
Juancki
  • 1,793
  • 1
  • 14
  • 21