AMQP-CPP >处理程序中的错误文件描述符
AMQP-CPP > Bad file descriptor in handler
我正在尝试使用 AMQP-CPP 库进行消息传递,但我无法使其工作。我想将库中已经构建的类用于通道、连接、处理程序。我从他们的例子开始,但每次运行代码时Bad file descriptor
我都会收到错误并且进程结束。我的代码看起来像这样
#include <amqpcpp.h>
#include <amqpcpp/libboostasio.h>
#include <boost/asio/io_service.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/deadline_timer.hpp>
class MyHandler : public AMQP::LibBoostAsioHandler
{
public:
MyHandler(boost::asio::io_service& service)
: AMQP::LibBoostAsioHandler(service)
{
}
virtual void onError(AMQP::TcpConnection *connection, const char *message) override
{
std::cout << "MyHandler::onError " << message << std::endl;
}
};
int main()
{
// access to the event loop
boost::asio::io_service service(2);
// handler for libevent
MyHandler handler(service);
// make a connection
AMQP::TcpConnection connection(&handler, AMQP::Address("amqp://localhost/"));
// we need a channel too
AMQP::TcpChannel channel(&connection);
channel.onError([](const char *message) {
// report error
std::cout << "channel error: " << message << std::endl;
});
channel.onReady([]() {
// send the first instructions (like publishing messages)
std::cout << "channel onReady: " << std::endl;
});
// create a temporary queue
channel.declareQueue("aaa").onSuccess([&connection](const std::string& name, uint32_t messagecount, uint32_t consumercount) {
// report the name of the temporary queue
std::cout << "declared queue " << name << std::endl;
// now we can close the connection
connection.close();
});
auto startCb = [](const std::string &consumertag) {
std::cout << "consume operation started" << std::endl;
};
// callback function that is called when the consume operation failed
auto errorCb = [](const char *message) {
std::cout << "consume operation failed" << std::endl;
};
// callback operation when a message was received
auto messageCb = [&channel](const AMQP::Message &message, uint64_t deliveryTag, bool redelivered) {
std::cout << "message received" << std::endl;
// acknowledge the message
channel.ack(deliveryTag);
};
channel.consume("aaa").onReceived(messageCb)
.onSuccess(startCb)
.onError(errorCb);
// run the loop
service.run();
return 0;
}
输出:
MyHandler::onError 错误的文件描述符
此外,线路上也发生错误service.run();
我也用libevent
尝试过类似的事情。
这里出了什么问题以及如何解决?有什么想法吗?
实际上,有两个问题。
首先,应该使用libev
,因为这是官方支持的。其次,确保您的 RabbitMQ 服务器正在运行。您可以在此处找到更多详细信息。
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 如何在文件和行号中抛出错误
- 防止在C++中选择错误文件时提升 xml 解析器崩溃
- AMQP-CPP >处理程序中的错误文件描述符
- Xcode OSX上的C++构建失败,出现多个错误文件IO..不可用:在macOS 10.15中引入
- 为什么生成文件返回 g++: 错误: h 文件或目录 make: *** [生成文件:12: 测试] 错误 1?
- 警告:打开错误文件(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.
- Ubuntu C++ 编译器错误: g++: 错误: 文件.cpp: 没有这样的文件或目录
- main.cc:5:30:致命错误:文件夹/file.h:没有这样的文件或目录
- C++ LNK2005"已定义"错误 - 文件引用自身
- C++:模拟餐饮公司计费程序-无法将错误数据输出到错误文件
- 博兰德C++链接器错误c文件包括
- Visual Studio 2015 代码覆盖率错误文件
- 使用system()与Gnuplot进行绘图会导致错误:文件不可读
- 是否存在fseek/ftell可能给出错误文件大小的情况
- g++编译错误.h文件
- c++编译错误:.o文件未找到
- 打开错误文件的错误消息
- Ndk-build输出添加符号错误.文件格式错误