From 2abbb577c90594481a457f4266660611dde19d48 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 8 Aug 2010 14:45:27 +0200 Subject: [PATCH] amqp plugin: Enable the "ExchangeType" option in Publish blocks, too. --- src/amqp.c | 58 +++++++++++++++++++++++++++++++-------------------- src/collectd.conf.pod | 6 ++++-- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/amqp.c b/src/amqp.c index 7b9f41b2..d6cd2756 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -220,6 +220,37 @@ static char *camqp_strerror (camqp_config_t *conf, /* {{{ */ return (buffer); } /* }}} char *camqp_strerror */ +static int camqp_create_exchange (camqp_config_t *conf) /* {{{ */ +{ + amqp_exchange_declare_ok_t *ed_ret; + + if (conf->exchange_type == NULL) + return (0); + + ed_ret = amqp_exchange_declare (conf->connection, + /* channel = */ CAMQP_CHANNEL, + /* exchange = */ amqp_cstring_bytes (conf->exchange), + /* type = */ amqp_cstring_bytes (conf->exchange_type), + /* passive = */ 0, + /* durable = */ 0, + /* auto_delete = */ 1, + /* arguments = */ AMQP_EMPTY_TABLE); + if ((ed_ret == NULL) && camqp_is_error (conf)) + { + char errbuf[1024]; + ERROR ("amqp plugin: amqp_exchange_declare failed: %s", + camqp_strerror (conf, errbuf, sizeof (errbuf))); + camqp_close_connection (conf); + return (-1); + } + + INFO ("amqp plugin: Successfully created exchange \"%s\" " + "with type \"%s\".", + conf->exchange, conf->exchange_type); + + return (0); +} /* }}} int camqp_create_exchange */ + static int camqp_setup_queue (camqp_config_t *conf) /* {{{ */ { amqp_queue_declare_ok_t *qd_ret; @@ -261,29 +292,6 @@ static int camqp_setup_queue (camqp_config_t *conf) /* {{{ */ { amqp_queue_bind_ok_t *qb_ret; - /* create the exchange */ - if (conf->exchange_type != NULL) - { - amqp_exchange_declare_ok_t *ed_ret; - - ed_ret = amqp_exchange_declare (conf->connection, - /* channel = */ CAMQP_CHANNEL, - /* exchange = */ amqp_cstring_bytes (conf->exchange), - /* type = */ amqp_cstring_bytes (conf->exchange_type), - /* passive = */ 0, - /* durable = */ 0, - /* auto_delete = */ 1, - /* arguments = */ AMQP_EMPTY_TABLE); - if ((ed_ret == NULL) && camqp_is_error (conf)) - { - char errbuf[1024]; - ERROR ("amqp plugin: amqp_exchange_declare failed: %s", - camqp_strerror (conf, errbuf, sizeof (errbuf))); - camqp_close_connection (conf); - return (-1); - } - } - assert (conf->queue != NULL); qb_ret = amqp_queue_bind (conf->connection, /* channel = */ CAMQP_CHANNEL, @@ -386,6 +394,10 @@ static int camqp_connect (camqp_config_t *conf) /* {{{ */ INFO ("amqp plugin: Successfully opened connection to vhost \"%s\" " "on %s:%i.", CONF(conf, vhost), CONF(conf, host), conf->port); + status = camqp_create_exchange (conf); + if (status != 0) + return (status); + if (!conf->publish) return (camqp_setup_queue (conf)); return (0); diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 195ad79f..36245e2c 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -170,6 +170,7 @@ possibly filtering or messages. User "guest" Password "guest" Exchange "amq.fanout" + # ExchangeType "fanout" # RoutingKey "collectd" # Persistent false # Format "command" @@ -230,10 +231,11 @@ In I blocks this option is optional. If given, a I between the given exchange and the I is created, using the I if configured. See the B and B options below. -=item B I (Subscribe only) +=item B I If given, the plugin will try to create the configured I with this -I after connecting and bind its I to it. +I after connecting. When in a I block, the I will then +be bound to this exchange. =item B I (Subscribe only) -- 2.11.0