]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8306 #resolve if the exchange doesn't exist, then create it, else
authorWilliam King <william.king@quentustech.com>
Sat, 10 Oct 2015 23:30:16 +0000 (16:30 -0700)
committerWilliam King <william.king@quentustech.com>
Sat, 10 Oct 2015 23:30:28 +0000 (16:30 -0700)
fail. This resolves several error cases.

src/mod/event_handlers/mod_amqp/mod_amqp_command.c

index c20ae3d937dbaa69b8e51128f52e93f25b07ae95..bb7ce5451ecd520672af8494a9b34a854852149a 100644 (file)
@@ -151,11 +151,8 @@ switch_status_t mod_amqp_command_create(char *name, switch_xml_t cfg)
                }
        }
        profile->conn_active = NULL;
-
-       if ( mod_amqp_connection_open(profile->conn_root, &(profile->conn_active), profile->name, profile->custom_attr) != SWITCH_STATUS_SUCCESS) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile[%s] was unable to connect to any connection\n", profile->name);
-       }
-
+       /* We are not going to open the command queue connection on create, but instead wait for the running thread to open it */
+       
        /* Start the worker threads */
        switch_threadattr_create(&thd_attr, profile->pool);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -200,6 +197,19 @@ void * SWITCH_THREAD_FUNC mod_amqp_command_thread(switch_thread_t *thread, void
                                continue;
                        }
 
+                       /* Check if exchange already exists */ 
+                       amqp_exchange_declare(profile->conn_active->state, 1,
+                                                                 amqp_cstring_bytes(profile->exchange),
+                                                                 amqp_cstring_bytes("topic"),
+                                                                 0, /* passive */
+                                                                 1, /* durable */
+                                                                 amqp_empty_table);
+
+                       if (mod_amqp_log_if_amqp_error(amqp_get_rpc_reply(profile->conn_active->state), "Checking for command exchange")) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Profile[%s] failed to create missing command exchange", profile->name);
+                               continue;
+                       }
+
                        /* Ensure we have a queue */
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Creating command queue");
                        recv_queue = amqp_queue_declare(profile->conn_active->state, // state