github.com/Jeffail/benthos/v3@v3.65.0/lib/input/nats_stream.go (about) 1 package input 2 3 import ( 4 "github.com/Jeffail/benthos/v3/internal/docs" 5 "github.com/Jeffail/benthos/v3/internal/impl/nats/auth" 6 "github.com/Jeffail/benthos/v3/lib/input/reader" 7 "github.com/Jeffail/benthos/v3/lib/log" 8 "github.com/Jeffail/benthos/v3/lib/message/batch" 9 "github.com/Jeffail/benthos/v3/lib/metrics" 10 "github.com/Jeffail/benthos/v3/lib/types" 11 "github.com/Jeffail/benthos/v3/lib/util/tls" 12 ) 13 14 //------------------------------------------------------------------------------ 15 16 func init() { 17 Constructors[TypeNATSStream] = TypeSpec{ 18 constructor: fromSimpleConstructor(NewNATSStream), 19 Summary: ` 20 Subscribe to a NATS Stream subject. Joining a queue is optional and allows 21 multiple clients of a subject to consume using queue semantics.`, 22 Description: ` 23 Tracking and persisting offsets through a durable name is also optional and 24 works with or without a queue. If a durable name is not provided then subjects 25 are consumed from the most recently published message. 26 27 When a consumer closes its connection it unsubscribes, when all consumers of a 28 durable queue do this the offsets are deleted. In order to avoid this you can 29 stop the consumers from unsubscribing by setting the field 30 ` + "`unsubscribe_on_close` to `false`" + `. 31 32 ### Metadata 33 34 This input adds the following metadata fields to each message: 35 36 ` + "``` text" + ` 37 - nats_stream_subject 38 - nats_stream_sequence 39 ` + "```" + ` 40 41 You can access these metadata fields using 42 [function interpolation](/docs/configuration/interpolation#metadata). 43 44 ` + auth.Description(), 45 FieldSpecs: docs.FieldSpecs{ 46 func() docs.FieldSpec { 47 b := batch.FieldSpec() 48 b.IsDeprecated = true 49 return b 50 }(), 51 docs.FieldCommon( 52 "urls", 53 "A list of URLs to connect to. If an item of the list contains commas it will be expanded into multiple URLs.", 54 []string{"nats://127.0.0.1:4222"}, 55 []string{"nats://username:password@127.0.0.1:4222"}, 56 ).Array(), 57 docs.FieldCommon("cluster_id", "The ID of the cluster to consume from."), 58 docs.FieldCommon("client_id", "A client ID to connect as."), 59 docs.FieldCommon("queue", "The queue to consume from."), 60 docs.FieldCommon("subject", "A subject to consume from."), 61 docs.FieldCommon("durable_name", "Preserve the state of your consumer under a durable name."), 62 docs.FieldCommon("unsubscribe_on_close", "Whether the subscription should be destroyed when this client disconnects."), 63 docs.FieldAdvanced("start_from_oldest", "If a position is not found for a queue, determines whether to consume from the oldest available message, otherwise messages are consumed from the latest."), 64 docs.FieldAdvanced("max_inflight", "The maximum number of unprocessed messages to fetch at a given time."), 65 docs.FieldAdvanced("ack_wait", "An optional duration to specify at which a message that is yet to be acked will be automatically retried."), 66 tls.FieldSpec(), 67 auth.FieldSpec(), 68 }, 69 Categories: []Category{ 70 CategoryServices, 71 }, 72 } 73 } 74 75 //------------------------------------------------------------------------------ 76 77 // NewNATSStream creates a new NATSStream input type. 78 func NewNATSStream(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) { 79 var c reader.Async 80 var err error 81 if c, err = reader.NewNATSStream(conf.NATSStream, log, stats); err != nil { 82 return nil, err 83 } 84 c = reader.NewAsyncBundleUnacks(c) 85 if c, err = reader.NewAsyncBatcher(conf.NATSStream.Batching, c, mgr, log, stats); err != nil { 86 return nil, err 87 } 88 return NewAsyncReader(TypeNATSStream, true, c, log, stats) 89 } 90 91 //------------------------------------------------------------------------------