Skip to content

Commit

Permalink
Expose GCP PubSub PublishSettings to Gizmo users (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgulczynski authored and oliver-nyt committed Dec 20, 2019
1 parent aca1015 commit d6babf2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
14 changes: 13 additions & 1 deletion pubsub/gcp/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package gcp

import "github.com/kelseyhightower/envconfig"
import (
gpubsub "cloud.google.com/go/pubsub"
"github.com/kelseyhightower/envconfig"
)

// Config holds common credentials and config values for
// working with GCP PubSub.
Expand All @@ -9,6 +12,15 @@ type Config struct {

// For publishing
Topic string `envconfig:"GCP_PUBSUB_TOPIC"`

// Batch settings for GCP publisher
// See: https://godoc.org/cloud.google.com/go/pubsub#PublishSettings
// Notes:
// This config will not allow you to set zero values for PublishSettings.
// Applications using these settings should be aware that Publish requests
// will block until the lowest of the thresholds in PublishSettings is met.
PublishSettings gpubsub.PublishSettings

// For subscribing
Subscription string `envconfig:"GCP_PUBSUB_SUBSCRIPTION"`
}
Expand Down
21 changes: 19 additions & 2 deletions pubsub/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,26 @@ func NewPublisher(ctx context.Context, cfg Config, opts ...option.ClientOption)
if err != nil {
return nil, err
}

t := c.Topic(cfg.Topic)
// Update PublishSettings from cfg.PublishSettings
// but never set thresholds to 0.
if cfg.PublishSettings.DelayThreshold > 0 {
t.PublishSettings.DelayThreshold = cfg.PublishSettings.DelayThreshold
}
if cfg.PublishSettings.CountThreshold > 0 {
t.PublishSettings.CountThreshold = cfg.PublishSettings.CountThreshold
}
if cfg.PublishSettings.ByteThreshold > 0 {
t.PublishSettings.ByteThreshold = cfg.PublishSettings.ByteThreshold
}
if cfg.PublishSettings.NumGoroutines > 0 {
t.PublishSettings.NumGoroutines = cfg.PublishSettings.NumGoroutines
}
if cfg.PublishSettings.Timeout > 0 {
t.PublishSettings.Timeout = cfg.PublishSettings.Timeout
}
return &publisher{
topic: c.Topic(cfg.Topic),
topic: t,
}, nil
}

Expand Down

0 comments on commit d6babf2

Please sign in to comment.