}
String publishJobQName = CNS_PRODUCER_QUEUE_NAME_PREFIX + partition;
String queueUrl = CQSHandler.getRelativeCnsInternalQueueUrl(publishJobQName);
CQSMessage msg = null;
int waitTimeSecs = 0;
if (CMBProperties.getInstance().isCQSLongPollEnabled()) {
waitTimeSecs = CMBProperties.getInstance().getCMBRequestTimeoutSec();
}
List<CQSMessage> l = CQSHandler.receiveMessage(queueUrl, waitTimeSecs, 1);
if (l.size() > 0) {
msg = l.get(0);
}
CNSWorkerMonitor.getInstance().registerCQSServiceAvailable(true);
if (msg != null) {
// if long polling disabled and message found reset exponential backoff
if (!CMBProperties.getInstance().isCQSLongPollEnabled()) {
processingDelayMillis = 10;
}
CNSMessage publishMessage = CNSMessage.parseInstance(msg.getBody());
int messageExpirationSeconds = CMBProperties.getInstance().getCNSMessageExpirationSeconds();
if (messageExpirationSeconds != 0 && System.currentTimeMillis() - publishMessage.getTimestamp().getTime() > messageExpirationSeconds*1000) {
logger.error("event=deleting_publish_job reason=message_too_old topic_arn=" + publishMessage.getTopicArn());
CQSHandler.deleteMessage(queueUrl, msg.getReceiptHandle());
CMBControllerServlet.valueAccumulator.deleteAllCounters();
return true; // return true to avoid backoff
}
List<CNSEndpointPublishJob.CNSEndpointSubscriptionInfo> subscriptions = null;
long t1=System.currentTimeMillis();
try {
subscriptions = getSubscriptionsForTopic(publishMessage.getTopicArn());
} catch (TopicNotFoundException e) {
//delete this message/job since the topic was deleted.
logger.error("event=deleting_publish_job reason=topic_not_found topic_arn=" + publishMessage.getTopicArn());
CQSHandler.deleteMessage(queueUrl, msg.getReceiptHandle());
CMBControllerServlet.valueAccumulator.deleteAllCounters();
return true; // return true to avoid backoff
} catch (Exception ex) {
logger.error("event=skipping_publish_job reason=error_fetching_subscriptions", ex);
CMBControllerServlet.valueAccumulator.deleteAllCounters();
return true; // return true to avoid backoff
}
logger.debug("event=get_subscription_list ms="+(System.currentTimeMillis()-t1));
if (subscriptions != null && subscriptions.size() > 0) {
messageFound = true;
List<CNSEndpointPublishJob> epPublishJobs = createEndpointPublishJobs(publishMessage, subscriptions);
for (CNSEndpointPublishJob epPublishJob: epPublishJobs) {
String epQueueName = CMBProperties.getInstance().getCNSEndpointPublishQueueNamePrefix() + ((new Random()).nextInt(CMBProperties.getInstance().getCNSNumEndpointPublishJobQueues()));
String epQueueUrl = CQSHandler.getRelativeCnsInternalQueueUrl(epQueueName);
CQSHandler.sendMessage(epQueueUrl, epPublishJob.serialize());
}
}
CQSHandler.deleteMessage(queueUrl, msg.getReceiptHandle());
long ts2 = System.currentTimeMillis();
logger.debug("event=processed_producer_job cns_cqs_ms=" + CMBControllerServlet.valueAccumulator.getCounter(AccumulatorName.CNSCQSTime) + " resp_ms=" + (ts2 - ts1));
} else {