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

     1  package output
     2  
     3  import (
     4  	"github.com/Jeffail/benthos/v3/internal/docs"
     5  	"github.com/Jeffail/benthos/v3/internal/metadata"
     6  	"github.com/Jeffail/benthos/v3/lib/log"
     7  	"github.com/Jeffail/benthos/v3/lib/message/batch"
     8  	"github.com/Jeffail/benthos/v3/lib/metrics"
     9  	"github.com/Jeffail/benthos/v3/lib/output/writer"
    10  	"github.com/Jeffail/benthos/v3/lib/types"
    11  	"github.com/Jeffail/benthos/v3/lib/util/aws/session"
    12  	"github.com/Jeffail/benthos/v3/lib/util/retries"
    13  )
    14  
    15  //------------------------------------------------------------------------------
    16  
    17  func init() {
    18  	Constructors[TypeAWSSQS] = TypeSpec{
    19  		constructor: fromSimpleConstructor(NewAWSSQS),
    20  		Version:     "3.36.0",
    21  		Summary: `
    22  Sends messages to an SQS queue.`,
    23  		Description: `
    24  Metadata values are sent along with the payload as attributes with the data type
    25  String. If the number of metadata values in a message exceeds the message
    26  attribute limit (10) then the top ten keys ordered alphabetically will be
    27  selected.
    28  
    29  The fields ` + "`message_group_id` and `message_deduplication_id`" + ` can be
    30  set dynamically using
    31  [function interpolations](/docs/configuration/interpolation#bloblang-queries), which are
    32  resolved individually for each message of a batch.
    33  
    34  ### Credentials
    35  
    36  By default Benthos will use a shared credentials file when connecting to AWS
    37  services. It's also possible to set them explicitly at the component level,
    38  allowing you to transfer data across accounts. You can find out more
    39  [in this document](/docs/guides/cloud/aws).`,
    40  		Async:   true,
    41  		Batches: true,
    42  		FieldSpecs: docs.FieldSpecs{
    43  			docs.FieldCommon("url", "The URL of the target SQS queue."),
    44  			docs.FieldCommon("message_group_id", "An optional group ID to set for messages.").IsInterpolated(),
    45  			docs.FieldCommon("message_deduplication_id", "An optional deduplication ID to set for messages.").IsInterpolated(),
    46  			docs.FieldCommon("max_in_flight", "The maximum number of messages to have in flight at a given time. Increase this to improve throughput."),
    47  			docs.FieldCommon("metadata", "Specify criteria for which metadata values are sent as headers.").WithChildren(metadata.ExcludeFilterFields()...),
    48  			batch.FieldSpec(),
    49  		}.Merge(session.FieldSpecs()).Merge(retries.FieldSpecs()),
    50  		Categories: []Category{
    51  			CategoryServices,
    52  			CategoryAWS,
    53  		},
    54  	}
    55  
    56  	Constructors[TypeSQS] = TypeSpec{
    57  		constructor: fromSimpleConstructor(NewAmazonSQS),
    58  		Status:      docs.StatusDeprecated,
    59  		Summary: `
    60  Sends messages to an SQS queue.`,
    61  		Description: `
    62  ## Alternatives
    63  
    64  This output has been renamed to ` + "[`aws_sqs`](/docs/components/outputs/aws_sqs)" + `.
    65  
    66  Metadata values are sent along with the payload as attributes with the data type
    67  String. If the number of metadata values in a message exceeds the message
    68  attribute limit (10) then the top ten keys ordered alphabetically will be
    69  selected.
    70  
    71  The fields ` + "`message_group_id` and `message_deduplication_id`" + ` can be
    72  set dynamically using
    73  [function interpolations](/docs/configuration/interpolation#bloblang-queries), which are
    74  resolved individually for each message of a batch.
    75  
    76  ### Credentials
    77  
    78  By default Benthos will use a shared credentials file when connecting to AWS
    79  services. It's also possible to set them explicitly at the component level,
    80  allowing you to transfer data across accounts. You can find out more
    81  [in this document](/docs/guides/cloud/aws).`,
    82  		Async:   true,
    83  		Batches: true,
    84  		FieldSpecs: docs.FieldSpecs{
    85  			docs.FieldCommon("url", "The URL of the target SQS queue."),
    86  			docs.FieldCommon("message_group_id", "An optional group ID to set for messages.").IsInterpolated(),
    87  			docs.FieldCommon("message_deduplication_id", "An optional deduplication ID to set for messages.").IsInterpolated(),
    88  			docs.FieldCommon("max_in_flight", "The maximum number of messages to have in flight at a given time. Increase this to improve throughput."),
    89  			docs.FieldCommon("metadata", "Specify criteria for which metadata values are sent as headers.").WithChildren(metadata.ExcludeFilterFields()...),
    90  			batch.FieldSpec(),
    91  		}.Merge(session.FieldSpecs()).Merge(retries.FieldSpecs()),
    92  		Categories: []Category{
    93  			CategoryServices,
    94  			CategoryAWS,
    95  		},
    96  	}
    97  }
    98  
    99  //------------------------------------------------------------------------------
   100  
   101  // NewAWSSQS creates a new AmazonSQS output type.
   102  func NewAWSSQS(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
   103  	return newAmazonSQS(TypeAWSSQS, conf.AWSSQS, mgr, log, stats)
   104  }
   105  
   106  // NewAmazonSQS creates a new AmazonSQS output type.
   107  func NewAmazonSQS(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
   108  	return newAmazonSQS(TypeSQS, conf.SQS, mgr, log, stats)
   109  }
   110  
   111  func newAmazonSQS(name string, conf writer.AmazonSQSConfig, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
   112  	s, err := writer.NewAmazonSQSV2(conf, mgr, log, stats)
   113  	if err != nil {
   114  		return nil, err
   115  	}
   116  	var w Type
   117  	if conf.MaxInFlight == 1 {
   118  		w, err = NewWriter(name, s, log, stats)
   119  	} else {
   120  		w, err = NewAsyncWriter(name, conf.MaxInFlight, s, log, stats)
   121  	}
   122  	if err != nil {
   123  		return w, err
   124  	}
   125  	return NewBatcherFromConfig(conf.Batching, w, mgr, log, stats)
   126  }
   127  
   128  //------------------------------------------------------------------------------