github.com/Jeffail/benthos/v3@v3.65.0/lib/input/gcp_pubsub.go (about) 1 package input 2 3 import ( 4 "github.com/Jeffail/benthos/v3/internal/docs" 5 "github.com/Jeffail/benthos/v3/lib/input/reader" 6 "github.com/Jeffail/benthos/v3/lib/log" 7 "github.com/Jeffail/benthos/v3/lib/message/batch" 8 "github.com/Jeffail/benthos/v3/lib/metrics" 9 "github.com/Jeffail/benthos/v3/lib/types" 10 ) 11 12 //------------------------------------------------------------------------------ 13 14 func init() { 15 Constructors[TypeGCPPubSub] = TypeSpec{ 16 constructor: fromSimpleConstructor(NewGCPPubSub), 17 Summary: ` 18 Consumes messages from a GCP Cloud Pub/Sub subscription.`, 19 Description: ` 20 For information on how to set up credentials check out 21 [this guide](https://cloud.google.com/docs/authentication/production). 22 23 ### Metadata 24 25 This input adds the following metadata fields to each message: 26 27 ` + "``` text" + ` 28 - gcp_pubsub_publish_time_unix 29 - All message attributes 30 ` + "```" + ` 31 32 You can access these metadata fields using 33 [function interpolation](/docs/configuration/interpolation#metadata).`, 34 Categories: []Category{ 35 CategoryServices, 36 CategoryGCP, 37 }, 38 FieldSpecs: docs.FieldSpecs{ 39 docs.FieldCommon("project", "The project ID of the target subscription."), 40 docs.FieldCommon("subscription", "The target subscription ID."), 41 docs.FieldCommon("sync", "Enable synchronous pull mode."), 42 docs.FieldCommon("max_outstanding_messages", "The maximum number of outstanding pending messages to be consumed at a given time."), 43 docs.FieldCommon("max_outstanding_bytes", "The maximum number of outstanding pending messages to be consumed measured in bytes."), 44 func() docs.FieldSpec { 45 b := batch.FieldSpec() 46 b.IsDeprecated = true 47 return b 48 }(), 49 docs.FieldDeprecated("max_batch_count"), 50 }, 51 } 52 } 53 54 //------------------------------------------------------------------------------ 55 56 // NewGCPPubSub creates a new GCP Cloud Pub/Sub input type. 57 func NewGCPPubSub(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) { 58 // TODO: V4 Remove this. 59 if conf.GCPPubSub.MaxBatchCount > 1 { 60 log.Warnf("Field '%v.max_batch_count' is deprecated, use '%v.batching.count' instead.\n", conf.Type, conf.Type) 61 conf.GCPPubSub.Batching.Count = conf.GCPPubSub.MaxBatchCount 62 } 63 var c reader.Async 64 var err error 65 if c, err = reader.NewGCPPubSub(conf.GCPPubSub, log, stats); err != nil { 66 return nil, err 67 } 68 if c, err = reader.NewAsyncBatcher(conf.GCPPubSub.Batching, c, mgr, log, stats); err != nil { 69 return nil, err 70 } 71 c = reader.NewAsyncBundleUnacks(c) 72 return NewAsyncReader(TypeGCPPubSub, true, c, log, stats) 73 } 74 75 //------------------------------------------------------------------------------