diff --git a/src/remote_common.c b/src/remote_common.c index 12c1545..4ce8da0 100644 --- a/src/remote_common.c +++ b/src/remote_common.c @@ -64,14 +64,15 @@ bool die_on_error(int x, char const *context) return true; } -bool connect_broker(amqp_connection_state_t *conn) +bool connect_broker(amqp_connection_state_t *conn, const char *hostName) { amqp_socket_t *socket = NULL; + const char *host = (hostName != NULL) ? hostName : "localhost"; /* Connect to the rabbitmq broker */ *conn = amqp_new_connection(); socket = amqp_tcp_socket_new(*conn); - if (amqp_socket_open(socket, HOSTNAME, 5672) != AMQP_STATUS_OK) { + if (amqp_socket_open(socket, host, 5672) != AMQP_STATUS_OK) { ddprintf("%s\n", "The rabbitmq broker is closed"); goto destroy_connection; } diff --git a/src/remote_common.h b/src/remote_common.h index cb1805e..2e6797a 100644 --- a/src/remote_common.h +++ b/src/remote_common.h @@ -14,10 +14,9 @@ #include "amqp.h" #include "amqp_tcp_socket.h" -#define HOSTNAME "localhost" #define MSG_PREFIX "[dcurl-remote] " -bool connect_broker(amqp_connection_state_t *conn); +bool connect_broker(amqp_connection_state_t *conn, const char *hostName); bool declare_queue(amqp_connection_state_t *conn, amqp_channel_t channel, diff --git a/src/remote_interface.c b/src/remote_interface.c index da326c4..a7a8b5e 100644 --- a/src/remote_interface.c +++ b/src/remote_interface.c @@ -146,7 +146,7 @@ static bool Remote_init(RemoteImplContext *remote_ctx) memset(remote_ctx->slots, 0, remote_ctx->num_max_thread * sizeof(bool)); for (int i = 0; i < CONN_MAX; i++) { - if (!connect_broker(&remote_ctx->conn[i])) + if (!connect_broker(&remote_ctx->conn[i], NULL)) goto fail_to_init; } if (!declare_queue(&remote_ctx->conn[0], 1, "incoming_queue")) diff --git a/src/remote_worker.c b/src/remote_worker.c index f8df527..848fbc4 100644 --- a/src/remote_worker.c +++ b/src/remote_worker.c @@ -22,7 +22,7 @@ int main(int argc, char const *const *argv) dcurl_init(); - if (!connect_broker(&conn)) + if (!connect_broker(&conn, NULL)) goto fail; if (!set_consuming_queue(&conn, 1, "incoming_queue"))