github.com/Jeffail/benthos/v3@v3.65.0/lib/output/nats_stream.go (about) 1 package output 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/log" 7 "github.com/Jeffail/benthos/v3/lib/metrics" 8 "github.com/Jeffail/benthos/v3/lib/output/writer" 9 "github.com/Jeffail/benthos/v3/lib/types" 10 "github.com/Jeffail/benthos/v3/lib/util/tls" 11 ) 12 13 //------------------------------------------------------------------------------ 14 15 func init() { 16 Constructors[TypeNATSStream] = TypeSpec{ 17 constructor: fromSimpleConstructor(NewNATSStream), 18 Summary: ` 19 Publish to a NATS Stream subject.`, 20 Description: auth.Description(), 21 Async: true, 22 FieldSpecs: docs.FieldSpecs{ 23 docs.FieldCommon( 24 "urls", 25 "A list of URLs to connect to. If an item of the list contains commas it will be expanded into multiple URLs.", 26 []string{"nats://127.0.0.1:4222"}, 27 []string{"nats://username:password@127.0.0.1:4222"}, 28 ).Array(), 29 docs.FieldCommon("cluster_id", "The cluster ID to publish to."), 30 docs.FieldCommon("subject", "The subject to publish to."), 31 docs.FieldCommon("client_id", "The client ID to connect with."), 32 docs.FieldCommon("max_in_flight", "The maximum number of messages to have in flight at a given time. Increase this to improve throughput."), 33 tls.FieldSpec(), 34 auth.FieldSpec(), 35 }, 36 Categories: []Category{ 37 CategoryServices, 38 }, 39 } 40 } 41 42 //------------------------------------------------------------------------------ 43 44 // NewNATSStream creates a new NATSStream output type. 45 func NewNATSStream(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) { 46 w, err := writer.NewNATSStream(conf.NATSStream, log, stats) 47 if err != nil { 48 return nil, err 49 } 50 a, err := NewAsyncWriter(TypeNATSStream, conf.NATSStream.MaxInFlight, w, log, stats) 51 if err != nil { 52 return nil, err 53 } 54 return OnlySinglePayloads(a), nil 55 } 56 57 //------------------------------------------------------------------------------