github.com/Jeffail/benthos/v3@v3.65.0/lib/output/amqp.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/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  	"github.com/Jeffail/gabs/v2"
    12  )
    13  
    14  //------------------------------------------------------------------------------
    15  
    16  func init() {
    17  	Constructors[TypeAMQP] = TypeSpec{
    18  		constructor: fromSimpleConstructor(NewAMQP),
    19  		Description: `
    20  DEPRECATED: This output is deprecated and scheduled for removal in Benthos V4.
    21  Please use [` + "`amqp_0_9`" + `](/docs/components/outputs/amqp_0_9) instead.`,
    22  		Status: docs.StatusDeprecated,
    23  		FieldSpecs: docs.FieldSpecs{
    24  			docs.FieldString("urls",
    25  				"A list of URLs to connect to. The first URL to successfully establish a connection will be used until the connection is closed. If an item of the list contains commas it will be expanded into multiple URLs.",
    26  				[]string{"amqp://guest:guest@127.0.0.1:5672/"},
    27  				[]string{"amqp://127.0.0.1:5672/,amqp://127.0.0.2:5672/"},
    28  				[]string{"amqp://127.0.0.1:5672/", "amqp://127.0.0.2:5672/"},
    29  			).Array().AtVersion("3.58.0"),
    30  			docs.FieldDeprecated("url").OmitWhen(func(field, parent interface{}) (string, bool) {
    31  				return "field url is deprecated and should be omitted when urls is used",
    32  					len(gabs.Wrap(parent).S("urls").Children()) > 0
    33  			}),
    34  			docs.FieldCommon("exchange", "An AMQP exchange to publish to."),
    35  			docs.FieldAdvanced("exchange_declare", "Optionally declare the target exchange (passive).").WithChildren(
    36  				docs.FieldCommon("enabled", "Whether to declare the exchange."),
    37  				docs.FieldCommon("type", "The type of the exchange.").HasOptions(
    38  					"direct", "fanout", "topic", "x-custom",
    39  				),
    40  				docs.FieldCommon("durable", "Whether the exchange should be durable."),
    41  			),
    42  			docs.FieldCommon("key", "The binding key to set for each message.").IsInterpolated(),
    43  			docs.FieldCommon("type", "The type property to set for each message.").IsInterpolated(),
    44  			docs.FieldAdvanced("content_type", "The content type attribute to set for each message.").IsInterpolated(),
    45  			docs.FieldAdvanced("content_encoding", "The content encoding attribute to set for each message.").IsInterpolated(),
    46  			docs.FieldCommon("metadata", "Specify criteria for which metadata values are attached to objects as headers.").WithChildren(metadata.ExcludeFilterFields()...),
    47  			docs.FieldAdvanced("priority", "Set the priority of each message with a dynamic interpolated expression.", "0", `${! meta("amqp_priority") }`, `${! json("doc.priority") }`).IsInterpolated(),
    48  			docs.FieldCommon("max_in_flight", "The maximum number of messages to have in flight at a given time. Increase this to improve throughput."),
    49  			docs.FieldAdvanced("persistent", "Whether message delivery should be persistent (transient by default)."),
    50  			docs.FieldAdvanced("mandatory", "Whether to set the mandatory flag on published messages. When set if a published message is routed to zero queues it is returned."),
    51  			docs.FieldAdvanced("immediate", "Whether to set the immediate flag on published messages. When set if there are no ready consumers of a queue then the message is dropped instead of waiting."),
    52  			tls.FieldSpec(),
    53  		},
    54  	}
    55  }
    56  
    57  //------------------------------------------------------------------------------
    58  
    59  // NewAMQP creates a new AMQP output type.
    60  // TODO: V4 Remove this.
    61  func NewAMQP(conf Config, mgr types.Manager, log log.Modular, stats metrics.Type) (Type, error) {
    62  	log.Warnln("The amqp input is deprecated, please use amqp_0_9 instead.")
    63  	a, err := writer.NewAMQPV2(mgr, conf.AMQP, log, stats)
    64  	if err != nil {
    65  		return nil, err
    66  	}
    67  	return NewWriter(
    68  		"amqp", a, log, stats,
    69  	)
    70  }
    71  
    72  //------------------------------------------------------------------------------