ActiveMQ-cpp client abnormal application exit problem, activemq Client
The author uses ActiveMQ as the server for message distribution in the system. The Java Web program reads the database real-time records as the Producer, and the receiving end is the client program developed by C ++ Builder. It is resident in the lower right corner of the client, the pop-up window displays real-time messages.
During the test, it is found that when the client is disconnected (the network cable is unplugged) or the server is restarted, the client will exit directly, and windows does not report a program crash, which is hard to understand.
The Debug debugging code finds that the problem lies in the exception handling of the custom Concumer class, and CALLS exit (1 );
//SimpleAsyncConsumer. cpp [1]
Void SimpleAsyncConsumer: onException (const CMSException & ex AMQCPP_UNUSED)
{
Printf ("CMS Exception occurred.Shutting down client. \ n ");
Exit (1 );
}
After exit (1) is commented out, the problem is solved and the client will no longer exit unexpectedly. However, during the network disconnection test, the client cannot detect that the connection to the server is disconnected.
Status variable.
Void SimpleAsyncConsumer: onException (const CMSException & ex AMQCPP_UNUSED)
{
Printf ("CMS Exception occurred.Shutting down client. \ n ");
Connflag = false;
}The upper-layer caller detects the connection status in real time, releases resources when false is detected, and waits for a reconnection.
[1] reference: http://blog.sina.com.cn/s/blog_a459dcf501017ooh.html shaoming blog ActiveMQ complete C ++ client example (source code), the use of client concumer see this article.