我正在开发一个从具有专有属性集的 Tibco EMS 队列中使用的应用程序。我将能够在活动和待机模式下运行我的应用程序的多个实例。当应用程序处于待机模式时,它不应该为独占队列创建消费者。
我已经实施了以下解决方案,但正在寻找更好的方法来做到这一点?
目前正在使用 tibemsQueueInfo_GetReceiverCount() 来获取接收器计数。但是这个 API 提供了为队列创建的所有消费者,在此之前我必须再调用 2 个 API。
是否有一个 API 会返回队列有一个活跃的消费者?
status = tibemsAdmin_Create(&admin, server, userName, password, sslParams);
if (status != TIBEMS_OK)
{
baseUtils_print("tibemsAdmin_Create create failed: %s\n", tibemsStatus_GetText(status));
exit(1);
}
baseUtils_print("Amin creation successful\n");
status = tibemsAdmin_GetQueue(admin, &queueInfo, name);
if (status != TIBEMS_OK)
{
baseUtils_print("tibemsAdmin_GetQueue create failed: %s\n", tibemsStatus_GetText(status));
exit(1);
}
baseUtils_print("Admin GetQueue successful \n");
status = tibemsQueueInfo_GetReceiverCount(queueInfo, &receiverCount);
if (status != TIBEMS_OK)
{
baseUtils_print("tibemsQueueInfo_GetReceiverCount create failed: %s\n", tibemsStatus_GetText(status));
exit(1);
}
baseUtils_print("Queue: '%s', Active Consumers = '%d'\n",name, receiverCount);
bool flag = true;
int prevCount = 0;
while(receiverCount)
{
prevCount = receiverCount;
if(flag)
{
cout << "Consumer in Standby mode..."<<endl;
flag = false;;
}
std::this_thread::sleep_for(std::chrono::seconds(3));
status = tibemsAdmin_GetQueue(admin, &queueInfo, name);
if (status != TIBEMS_OK)
{
baseUtils_print("tibemsAdmin_GetQueue create failed: %s\n", tibemsStatus_GetText(status));
exit(1);
}
status = tibemsQueueInfo_GetReceiverCount(queueInfo, &receiverCount);
if (status != TIBEMS_OK)
{
baseUtils_print("tibemsQueueInfo_GetReceiverCount create failed: %s\n", tibemsStatus_GetText(status));
exit(1);
}
if(receiverCount != prevCount)
cout << "current receiver count = "<<receiverCount<<endl;
}
cout << "Consumer mode is Active"<<endl;
status = tibemsSession_CreateConsumer(session,
&msgConsumer,destination,NULL,TIBEMS_FALSE);
if (status != TIBEMS_OK)
{
fail("Error creating tibemsMsgConsumer", errorContext);
}