github.com/Jeffail/benthos/v3@v3.65.0/lib/input/nats.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/metrics"
     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[TypeNATS] = TypeSpec{
    17  		constructor: fromSimpleConstructor(NewNATS),
    18  		Summary: `
    19  Subscribe to a NATS subject.`,
    20  		Description: `
    21  ### Metadata
    22  
    23  This input adds the following metadata fields to each message:
    24  
    25  ` + "``` text" + `
    26  - nats_subject
    27  - All message headers (when supported by the connection)
    28  ` + "```" + `
    29  
    30  You can access these metadata fields using
    31  [function interpolation](/docs/configuration/interpolation#metadata).
    32  
    33  ` + auth.Description(),
    34  		FieldSpecs: docs.FieldSpecs{
    35  			docs.FieldCommon(
    36  				"urls",
    37  				"A list of URLs to connect to. If an item of the list contains commas it will be expanded into multiple URLs.",
    38  				[]string{"nats://127.0.0.1:4222"},
    39  				[]string{"nats://username:password@127.0.0.1:4222"},
    40  			).Array(),
    41  			docs.FieldCommon("queue", "The queue to consume from."),
    42  			docs.FieldCommon("subject", "A subject to consume from."),
    43  			docs.FieldAdvanced("prefetch_count", "The maximum number of messages to pull at a time."),
    44  			tls.FieldSpec(),
    45  			auth.FieldSpec(),
    46  		},
    47  		Categories: []Category{
    48  			CategoryServices,
    49  		},
    50  	}
    51  }
    52  
    53  //------------------------------------------------------------------------------
    54  
    55  // NewNATS creates a new NATS input type.
    56  func NewNATS(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
    57  	n, err := reader.NewNATS(conf.NATS, log, stats)
    58  	if err != nil {
    59  		return nil, err
    60  	}
    61  	return NewAsyncReader(TypeNATS, true, reader.NewAsyncPreserver(n), log, stats)
    62  }
    63  
    64  //------------------------------------------------------------------------------