Add option to amqp output to publish persistent messages (#3528)
This commit is contained in:
parent
1dee532574
commit
bca73f0923
|
@ -29,6 +29,9 @@ For an introduction to AMQP see:
|
|||
## Telegraf tag to use as a routing key
|
||||
## ie, if this tag exists, its value will be used as the routing key
|
||||
routing_tag = "host"
|
||||
## Delivery Mode controls if a published message is persistent
|
||||
## Valid options are "transient" and "persistent". default: "transient"
|
||||
# delivery_mode = "transient"
|
||||
|
||||
## InfluxDB retention policy
|
||||
# retention_policy = "default"
|
||||
|
|
|
@ -39,6 +39,9 @@ type AMQP struct {
|
|||
Precision string
|
||||
// Connection timeout
|
||||
Timeout internal.Duration
|
||||
// Delivery Mode controls if a published message is persistent
|
||||
// Valid options are "transient" and "persistent". default: "transient"
|
||||
DeliveryMode string
|
||||
|
||||
// Path to CA file
|
||||
SSLCA string `toml:"ssl_ca"`
|
||||
|
@ -52,6 +55,7 @@ type AMQP struct {
|
|||
sync.Mutex
|
||||
c *client
|
||||
|
||||
deliveryMode uint8
|
||||
serializer serializers.Serializer
|
||||
}
|
||||
|
||||
|
@ -82,6 +86,9 @@ var sampleConfig = `
|
|||
## Telegraf tag to use as a routing key
|
||||
## ie, if this tag exists, its value will be used as the routing key
|
||||
routing_tag = "host"
|
||||
## Delivery Mode controls if a published message is persistent
|
||||
## Valid options are "transient" and "persistent". default: "transient"
|
||||
delivery_mode = "transient"
|
||||
|
||||
## InfluxDB retention policy
|
||||
# retention_policy = "default"
|
||||
|
@ -111,6 +118,18 @@ func (a *AMQP) SetSerializer(serializer serializers.Serializer) {
|
|||
}
|
||||
|
||||
func (q *AMQP) Connect() error {
|
||||
switch q.DeliveryMode {
|
||||
case "transient":
|
||||
q.deliveryMode = amqp.Transient
|
||||
break
|
||||
case "persistent":
|
||||
q.deliveryMode = amqp.Persistent
|
||||
break
|
||||
default:
|
||||
q.deliveryMode = amqp.Transient
|
||||
break
|
||||
}
|
||||
|
||||
headers := amqp.Table{
|
||||
"database": q.Database,
|
||||
"retention_policy": q.RetentionPolicy,
|
||||
|
@ -248,6 +267,7 @@ func (q *AMQP) Write(metrics []telegraf.Metric) error {
|
|||
Headers: c.headers,
|
||||
ContentType: "text/plain",
|
||||
Body: buf,
|
||||
DeliveryMode: q.deliveryMode,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to send AMQP message: %s", err)
|
||||
|
|
Loading…
Reference in New Issue