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