【发布时间】:2019-09-13 14:17:49
【问题描述】:
我是 RabbitMQ 的新手。
我在 Windows 10 上安装了 RabbitMQ 服务器。我可以在 Web 浏览器中登录服务器。当我运行下面的客户端代码(使用 AMQP-CPP 库)时,不会调用 channel.onSuccess 或 channel.onError。而且,我在网络浏览器中看不到我声明的 my-queue 队列和 my-exchange 交换。
如果我理解正确,我需要添加一些事件循环(?)。但是,我找不到任何适用于 Windows 的示例。你能解释一下可能是什么问题吗?
int main()
{
// create an instance of your own tcp handler
MyTcpHandler myHandler;
// address of the server
//AMQP::Address address("amqp://guest:guest@localhost:5672/");
AMQP::Address address("localhost", 15672, AMQP::Login("guest", "guest"), "");
// create a AMQP connection object
AMQP::TcpConnection connection(&myHandler, address);
// and create a channel b
AMQP::TcpChannel channel(&connection);
// use the channel object to call the AMQP method you like
channel.declareExchange("my-exchange", AMQP::fanout)
.onSuccess([]()
{
std::cout << "declared exchange " << std::endl;
}).onError([](const char *message)
{
std::cout << "error: " << message << std::endl;
});
channel.declareQueue("my-queue");
channel.bindQueue("my-exchange", "my-queue", "my-routing-key");
std::cout << "Press Enter..." << std::endl;
std::getchar();
return 0;
}
MyTcpHandler
class MyTcpHandler : public AMQP::TcpHandler
{
public:
virtual void onConnected(AMQP::TcpConnection *connection) {}
virtual void onError(AMQP::TcpConnection *connection, const char *message) {}
virtual void onClosed(AMQP::TcpConnection *connection) {}
virtual void monitor(AMQP::TcpConnection *connection, AMQP::tcp::Socket fd, int flags) {}
};
【问题讨论】: