RabbitMQ在调用amqp_login时关闭套接字

zbq4xfa0  于 2023-10-20  发布在  RabbitMQ
关注(0)|答案(1)|浏览(170)

我使用..\rabbitmq-c\examples的示例代码来创建到http://localhost:15672的连接。从下面的代码块中,我得到:Logging in: socket is closed输出

amqp_socket_t *socket = NULL;
  amqp_connection_state_t conn;

  hostname = "localhost";
  port = 131072;  // 15672 // 131072
  username = "guest";
  password = "guest";
  exchange = "testExchange";
  bindingKey = "testMessage";
  queueName = "testQueue";
  routingKey = "testMessage";
  messageBody = "testMessageBody";

  conn = amqp_new_connection();

  socket = amqp_tcp_socket_new(conn);
  if (!socket)
  {
    die("Creating TCP socket ERROR");
  }

  status = amqp_socket_open(socket, hostname, port);
  if (!status)
  {
    die("Opening TCP socket ERROR");
  }

  die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN,
    "guest", "guest"),
    "Logging in");
  amqp_channel_open(conn, 1);
  die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel");

rabbitmq-c是用VS2015编译的,我有rabbitmq-server 3.7.6,它已经在运行了。

ubbxdtey

ubbxdtey1#

RabbitMQ在5672端口上运行,您正在尝试连接到131072端口。考虑到TCP允许的最大端口是65535,这是不可能的。
将您的代码更改为使用5672

相关问题