Skip to content
This repository has been archived by the owner on Jun 20, 2020. It is now read-only.

Commit

Permalink
Add setting to avoid subscription creation (#15)
Browse files Browse the repository at this point in the history
Add a configuration property that will skip attempting to create the
pubsub subscription.

For #13

Note the default subscriber role still will not work, minimal
permissions can be granted as described here
googleapis/google-cloud-node#1502 (comment).
  • Loading branch information
Chris Koehnke authored and josephlewis42 committed Oct 23, 2018
1 parent 2675ed5 commit c7dd7d4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
13 changes: 13 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
The following is a list of people who have contributed ideas, code, bug
reports, or in general have helped pubsubbeat along its way.

Contributors:

* Chris Koehnke ([email protected])
* Joseph Lewis III ([email protected])
* Vincent Roseberry ([email protected])

Note: If you've sent us patches, bug reports, or otherwise contributed to
pubsubbeat, and you aren't on the list above and want to be, please let us know
and we'll make sure you're here. Contributions from folks like you are what make
open source awesome.
5 changes: 5 additions & 0 deletions beater/pubsubbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ func createPubsubClient(config *config.Config) (*pubsub.Client, error) {
}

func getOrCreateSubscription(client *pubsub.Client, config *config.Config) (*pubsub.Subscription, error) {
if !config.Subscription.Create {
subscription := client.Subscription(config.Subscription.Name)
return subscription, nil
}

topic := client.Topic(config.Topic)
ctx := context.Background()

Expand Down
9 changes: 8 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ type Config struct {
Name string `config:"name" validate:"required"`
RetainAckedMessages bool `config:"retain_acked_messages"`
RetentionDuration time.Duration `config:"retention_duration"`
Create bool `config:"create"`
}
Json struct {
Enabled bool `config:"enabled"`
AddErrorKey bool `config:"add_error_key"`
}
}

var DefaultConfig = Config{}
func GetDefaultConfig() Config {
config := Config{}
config.Subscription.Create = true
return config
}

var DefaultConfig = GetDefaultConfig()

func GetAndValidateConfig(cfg *common.Config) (*Config, error) {
c := DefaultConfig
Expand Down
6 changes: 4 additions & 2 deletions pubsubbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ pubsubbeat:
# The Pub/Sub topic name. You must first create this topic.
topic: my-topic

# The Pub/Sub subscription name. If the subscription does not exist,
# Pubsubbeat will attempt to create the subscription.
# The Pub/Sub subscription name.
subscription.name: my-subscription

# Attempt to create the subscription.
subscription.create: true # Defaults to true

# The settings below are used only if the Beat creates the subscription.

# Whether to retain acknowledged messages. If true, acknowledged messages
Expand Down

0 comments on commit c7dd7d4

Please sign in to comment.