首先,感谢您提供讨论问题的平台。

我发现qpid cpp客户端程序有问题。

try{
cout << "Trying to open a connection" << endl;
connection.open("1.1.1.8", 10002);
session = connection.newSession();
SubscriptionManager subscriptions(session);
Listener listener(subscriptions);
subscriptions.subscribe(listener, receiver_queue);
//    subscriptions.run();
   subscriptions.start();
   sleep(10);
  }
 catch(const std::exception& error) {
  DEBUG(DBG_ERR, (char *)"AMQP-[%s]: Connection Error [%s].", __func__,error.what());
    connection.close();
   return RESULT_FAILURE;
 }


subscriptions.start之后,如果我向客户端程序发送任何消息,则可以看到已收到消息,但失败,但以下异常。

terminate called after throwing an instance of 'qpid::Exception'
  what():  Invalid argument (../include/qpid/sys/posix/Mutex.h:116)
Aborted


堆栈说..

(gdb) bt
#0  0x0024b424 in __kernel_vsyscall ()
#1  0x00276af1 in raise () from /lib/libc.so.6
#2  0x002783ca in abort () from /lib/libc.so.6
#3  0x0026fdcb in __assert_fail_base () from /lib/libc.so.6
#4  0x0026fe86 in __assert_fail () from /lib/libc.so.6
#5  0x00b683b6 in unlock (this=0x88501fc, name="A.B.ToApplication")
at ../include/qpid/sys/posix/Mutex.h:120
#6  ~ScopedLock (this=0x88501fc, name="A.B.ToApplication")
at        .    ./include/qpid/sys/Mutex.h:34
#7  qpid::client::Dispatcher::find (this=0x88501fc,
  name="A.B.ToApplication")
 at qpid/client/Dispatcher.cpp:137
#8  0x00b68752 in qpid::client::Dispatcher::run (this=0x88501fc) at
qpid/client/Dispatcher.cpp:83
#9  0x00d5b701 in qpid::sys::(anonymous namespace)::runRunnable (p=0x88501fc) at
qpid/sys/posix/Thread.cpp:35
#10 0x00564a09 in start_thread () from /lib/libpthread.so.0
#11 0x0032915e in clone () from /lib/libc.so.6
(gdb)


我在这里想念什么吗?

请帮我。

最佳答案

不要使用SubscriptionManager :: start()-因为不允许处理异常,它已损坏-请改用SubscriptionManager :: run(),并在需要时产生一个新线程。

我也强烈建议您使用qpid :: messaging API,而不要使用旧的qpid :: client API。前者更简单,将允许更轻松地过渡到AMQP 1.0,这就是所有新开发都将发生的地方。

关于c++ - qpid cpp客户端中收到传入消息时出现异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11964449/

10-11 18:21