Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add queue_durability property to amqp_consumer input #4628

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/inputs/amqp_consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ The following defaults are known to work with RabbitMQ:

## AMQP queue name
queue = "telegraf"

## AMQP queue durability can be "transient" or "durable".
queue_durability = "durable"

## Binding Key
binding_key = "#"

Expand Down
34 changes: 25 additions & 9 deletions plugins/inputs/amqp_consumer/amqp_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type AMQPConsumer struct {
ExchangeArguments map[string]string `toml:"exchange_arguments"`

// Queue Name
Queue string
Queue string `toml:"queue"`
QueueDurability string `toml:"queue_durability"`

// Binding Key
BindingKey string `toml:"binding_key"`

Expand Down Expand Up @@ -64,6 +66,8 @@ const (
DefaultExchangeType = "topic"
DefaultExchangeDurability = "durable"

DefaultQueueDurability = "durable"

DefaultPrefetchCount = 50
)

Expand Down Expand Up @@ -98,10 +102,13 @@ func (a *AMQPConsumer) SampleConfig() string {
# exchange_arguments = { }
# exchange_arguments = {"hash_propery" = "timestamp"}

## AMQP queue name
## AMQP queue name.
queue = "telegraf"

## Binding Key
## AMQP queue durability can be "transient" or "durable".
queue_durability = "durable"

## Binding Key.
binding_key = "#"

## Maximum number of messages server should give to the worker.
Expand Down Expand Up @@ -260,13 +267,21 @@ func (a *AMQPConsumer) connect(amqpConf *amqp.Config) (<-chan amqp.Delivery, err
return nil, err
}

var queueDurable = true
switch a.QueueDurability {
case "transient":
queueDurable = false
default:
queueDurable = true
}

q, err := ch.QueueDeclare(
a.Queue, // queue
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
a.Queue, // queue
queueDurable, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
if err != nil {
return nil, fmt.Errorf("Failed to declare a queue: %s", err)
Expand Down Expand Up @@ -380,6 +395,7 @@ func init() {
AuthMethod: DefaultAuthMethod,
ExchangeType: DefaultExchangeType,
ExchangeDurability: DefaultExchangeDurability,
QueueDurability: DefaultQueueDurability,
PrefetchCount: DefaultPrefetchCount,
}
})
Expand Down