Default settings and options
Configure default settings
You can efficiently process messages by configuring publish and receive (pull) settings.
Publish settings
Item | Description |
---|---|
DelayThreshold | Sends publish requests at defined intervals - Default: 100ms |
CountThreshold | Sends messages in batch when the specified count is reached - Default: 100 |
NumGoroutines | Limits the number of concurrently running goroutines - Default: 2 - Max: 10 |
Timeout | Timeout duration for publish requests - Default: 60s |
FlowControlSettings | Controls the publish rate through flow control settings |
Receive settings
Item | Description |
---|---|
NumGoroutines | Limits the number of concurrently running goroutines - Default: 2 - Max: 10 |
FlowControlSettings | Controls the receive rate through flow control settings |
Flow control settings
Item | Description |
---|---|
MaxOutstandingMessages | Maximum number of messages that can be held in the internal buffer - Default: 1000 |
MaxOutstandingBytes | Maximum size of messages that can be held in the internal buffer - Default: 1G |
LimitExceededBehavior | Behavior when the threshold is exceeded • SignalError : Returns an error• Block (Default): Waits until request can proceed without exceeding limits⚠️ Useful in batch processing scenarios where individual request latency is not critical • Ignore : Disables flow control |
Retry
When gRPC calls return specific error codes, retry attempts are made based on configured retry options. The default retry codes and settings per API are listed below.
Retry error status codes
Refer to gRPC status code documentation for more information.
Code | Description |
---|---|
CANCELLED | Call was cancelled (usually by the client) |
UNKNOWN | Unknown error, possibly due to unexpected status from a different address Also occurs when the API does not return specific error info |
DEADLINE_EXCEEDED | Deadline expired before the call completed |
NOT_FOUND | Requested entity not found |
RESOURCE_EXHAUSTED | Resource quota exceeded or system storage full |
ABORTED | Operation aborted due to concurrency conflict (e.g., failed sequencer check) |
INTERNAL | Internal server error |
UNAVAILABLE | Service is currently unavailable |
Retry configuration options
Item | Description |
---|---|
Initial | Initial delay before first retry - Adjusted by Multiplier |
Multiplier | Next retry delay = previous retry delay × Multiplier |
Max | Maximum retry delay ⚠️ Multiplier cannot increase delay beyond this limit |
Publisher retry default setting
API | Retry code | Description | Retry setting |
---|---|---|---|
create topic | 14 | UNAVAILABLE | • Initial: 100ms • Multiplier: 1.3 • Max: 60s |
get topic | 14 | UNAVAILABLE | - |
list topics | 14 | UNAVAILABLE | - |
list topic subscriptions | 14 | UNAVAILABLE | - |
update topic | 14 | UNAVAILABLE | - |
delete topic | 14 | UNAVAILABLE | - |
publish | 1 | CANCELLED | - |
4 | DEADLINE_EXCEEDED | - | |
8 | RESOURCE_EXHAUSTED | - | |
13 | INTERNAL | - | |
14 | UNAVAILABLE | - |
Subscriber retry default setting
API | Retry code | Description | Retry setting |
---|---|---|---|
create subscription | 14 | UNAVAILABLE | • Initial: 100ms • Multiplier: 1.3 • Max: 60s |
get subscription | 14 | UNAVAILABLE | - |
list subscriptions | 14 | UNAVAILABLE | - |
seek | 14 | UNAVAILABLE | - |
update subscription | 14 | UNAVAILABLE | - |
delete subscription | 14 | UNAVAILABLE | - |
modify ack deadline | 14 | UNAVAILABLE | - |
acknowledge | 14 | UNAVAILABLE | - |
pull | 14 | UNAVAILABLE | - |
streaming pull | 4 | DEADLINE_EXCEEDED | - |
8 | RESOURCE_EXHAUSTED | - | |
13 | INTERNAL | - | |
14 | UNAVAILABLE | - |
Example: Custom retry configuration
cfg := &pubsub.ClientConfig{
PublisherCallOptions: &api.PublisherCallOptions{
Publish: []option.CallOption{
option.WithRetryOptions(
option.WithCodes(codes.ResourceExhausted),
option.WithBackoff(option.Backoff{
Initial: 100 * time.Millisecond,
Max: 30000 * time.Millisecond,
Multiplier: 1.20,
})),
},
},
SubscriberCallOptions: &api.SubscriberCallOptions{
StreamingPull: []option.CallOption{
option.WithRetryOptions(
option.WithCodes(codes.ResourceExhausted),
option.WithBackoff(option.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.30,
})),
},
},
}
client, err := NewClientWithConfig(ctx, domainID, projectID, cfg, opts...)
Logging
You can record statistical logs of request and response results (success/failure) from Publish and StreamingPull operations.
- When a time interval is configured, the number of successful and failed publish and pull attempts is logged periodically.
- To view logs, the logging level must be set to
info
or higher.
The logger supports the following configuration options:
Item | Description |
---|---|
Level | Log level - Default: Panic |
Output | Log output destination - Default: os.Stdout |
StatLogInterval | Interval at which logs are written |
Logging example
conf := &ClientConfig{
LogOptions: &LogOptions{
Level: "info",
Output: os.Stdout,
StatLogInterval: 1 * time.Second
}
}
client, err := NewClientWithConfig(ctx, domainID, projectID, conf, opts...)