I am developing an application which consumes from a Tibco EMS Queue which has exclusive property set. I shall be able to run multiple instances of my application in Active and Standby mode. When the application is in standby mode it should not create a consumer to the exclusive queue.
I have implemented the below solution but am looking for a better way to do this?
Currently am using tibemsQueueInfo_GetReceiverCount() to get the receiver count. But this API gives all the consumers created for the queue and I have to call 2 more APIs before this.
Is there a single API that would just return that the queue has an active consumer?
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);
}