@@ -39,6 +39,9 @@ type AMQP struct {
39
39
Precision string
40
40
// Connection timeout
41
41
Timeout internal.Duration
42
+ // Delivery Mode controls if a published message is persistent
43
+ // Valid options are "transient" and "persistent". default: "transient"
44
+ DeliveryMode string
42
45
43
46
// Path to CA file
44
47
SSLCA string `toml:"ssl_ca"`
@@ -52,7 +55,8 @@ type AMQP struct {
52
55
sync.Mutex
53
56
c * client
54
57
55
- serializer serializers.Serializer
58
+ deliveryMode uint8
59
+ serializer serializers.Serializer
56
60
}
57
61
58
62
type externalAuth struct {}
@@ -82,6 +86,9 @@ var sampleConfig = `
82
86
## Telegraf tag to use as a routing key
83
87
## ie, if this tag exists, its value will be used as the routing key
84
88
routing_tag = "host"
89
+ ## Delivery Mode controls if a published message is persistent
90
+ ## Valid options are "transient" and "persistent". default: "transient"
91
+ delivery_mode = "transient"
85
92
86
93
## InfluxDB retention policy
87
94
# retention_policy = "default"
@@ -111,6 +118,18 @@ func (a *AMQP) SetSerializer(serializer serializers.Serializer) {
111
118
}
112
119
113
120
func (q * AMQP ) Connect () error {
121
+ switch q .DeliveryMode {
122
+ case "transient" :
123
+ q .deliveryMode = amqp .Transient
124
+ break
125
+ case "persistent" :
126
+ q .deliveryMode = amqp .Persistent
127
+ break
128
+ default :
129
+ q .deliveryMode = amqp .Transient
130
+ break
131
+ }
132
+
114
133
headers := amqp.Table {
115
134
"database" : q .Database ,
116
135
"retention_policy" : q .RetentionPolicy ,
@@ -245,9 +264,10 @@ func (q *AMQP) Write(metrics []telegraf.Metric) error {
245
264
false , // mandatory
246
265
false , // immediate
247
266
amqp.Publishing {
248
- Headers : c .headers ,
249
- ContentType : "text/plain" ,
250
- Body : buf ,
267
+ Headers : c .headers ,
268
+ ContentType : "text/plain" ,
269
+ Body : buf ,
270
+ DeliveryMode : q .deliveryMode ,
251
271
})
252
272
if err != nil {
253
273
return fmt .Errorf ("Failed to send AMQP message: %s" , err )
0 commit comments