github.com/Jeffail/benthos/v3@v3.65.0/lib/output/nsq.go (about)

     1  package output
     2  
     3  import (
     4  	"github.com/Jeffail/benthos/v3/internal/docs"
     5  	"github.com/Jeffail/benthos/v3/lib/log"
     6  	"github.com/Jeffail/benthos/v3/lib/metrics"
     7  	"github.com/Jeffail/benthos/v3/lib/output/writer"
     8  	"github.com/Jeffail/benthos/v3/lib/types"
     9  	"github.com/Jeffail/benthos/v3/lib/util/tls"
    10  )
    11  
    12  //------------------------------------------------------------------------------
    13  
    14  func init() {
    15  	Constructors[TypeNSQ] = TypeSpec{
    16  		constructor: fromSimpleConstructor(NewNSQ),
    17  		Summary: `
    18  Publish to an NSQ topic.`,
    19  		Description: `
    20  The ` + "`topic`" + ` field can be dynamically set using function interpolations
    21  described [here](/docs/configuration/interpolation#bloblang-queries). When sending
    22  batched messages these interpolations are performed per message part.`,
    23  		Async: true,
    24  		FieldSpecs: docs.FieldSpecs{
    25  			docs.FieldCommon("nsqd_tcp_address", "The address of the target NSQD server."),
    26  			docs.FieldCommon("topic", "The topic to publish to.").IsInterpolated(),
    27  			docs.FieldCommon("user_agent", "A user agent string to connect with."),
    28  			tls.FieldSpec(),
    29  			docs.FieldCommon("max_in_flight", "The maximum number of messages to have in flight at a given time. Increase this to improve throughput."),
    30  		},
    31  		Categories: []Category{
    32  			CategoryServices,
    33  		},
    34  	}
    35  }
    36  
    37  //------------------------------------------------------------------------------
    38  
    39  // NewNSQ creates a new NSQ output type.
    40  func NewNSQ(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
    41  	w, err := writer.NewNSQV2(conf.NSQ, mgr, log, stats)
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  	if conf.NSQ.MaxInFlight == 1 {
    46  		return NewWriter(TypeNSQ, w, log, stats)
    47  	}
    48  	return NewAsyncWriter(TypeNSQ, conf.NSQ.MaxInFlight, w, log, stats)
    49  }
    50  
    51  //------------------------------------------------------------------------------