材料:qpid-cpp-1.36.0.tar.gz
一般情况下,在qpid-cpp-1.36.0目录下创建build文件夹应用于VS解决方案生成
CMake配置如下:
Where is the source code:E:/bin/qpid-cpp-1.36.0
Where is build the binaries:E:/bin/qpid-cpp-1.36.0/build
BUILD_BINDING_DOTNET 取消编译
CMake点击Configure检测系统是否安装必须的依赖库,点击Generate生成VS2015解决方案,在
build目录下生成qpid-cpp.sln,当前编译Qpid的核心原因是Qpid Client客户端调用的DLL,出现
内存泄露,因此只需要打开examples文件夹下面的qpidc_examples.sln,进行代码的跟踪调试
qpidc_exmaples.sln配置,设置client作为启动项,
将boost库的DLL,qpidclientd.dll qpidcommond.dll qpidmessagingd.dll qpidtyped.dll还有相关的pdb文件拷贝到examples\messaging\Debug才能够调试源码
编写简单的测试程序:
int SimpleTest()
{
std::string broker = "localhost:5672";
std::string address = "amq.topic";
Connection connection(broker);
try {
connection.open();
Session session = connection.createSession();
while (1)
{
Receiver &receiver = session.createReceiver(address);
Sender &sender = session.createSender(address);
sender.send(Message("Hello world!"));
Message message = receiver.fetch(Duration::SECOND * 1);
std::cout << message.getContent() << std::endl;
session.acknowledge();
::Sleep(25);
}
session.close();
connection.close();
return -1;
}
catch (const std::exception& error) {
std::cerr << error.what() << std::endl;
connection.close();
return 0;
}
}
int main(int argc, char** argv)
{
while (1)
{
SimpleTest();
::Sleep(25);
}
return 0;
}
总结
不断的连接断开将造成内存泄露,如果保持长连接,只是进行消息的收发,就不会出现内存问题
本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/2071760,如需转载请自行联系原作者