Skip to content

Commit

Permalink
feat: Improve function for broker IP assignment
Browse files Browse the repository at this point in the history
Add extra parameter for RabbitMQ broker IP assignment.
Remove unnecessary macro.
  • Loading branch information
marktwtn committed Aug 29, 2019
1 parent da621cf commit d94878c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/remote_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/remote_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/remote_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion src/remote_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit d94878c

Please sign in to comment.