public Map<String, String> sendMessageBatch(CQSQueue queue, int shard, List<CQSMessage> messages) throws PersistenceException, IOException, InterruptedException, NoSuchAlgorithmException, JSONException {
persistenceStorage.sendMessageBatch(queue, shard, messages);
Map<String, String> memIds = new HashMap<String, String>();
boolean cacheAvailable = checkCacheConsistency(queue.getRelativeUrl(), shard, true);//set in cache even if its filling
ShardedJedis jedis = null;
if (cacheAvailable) {
try {
jedis = getResource();
} catch (JedisConnectionException e) {
cacheAvailable = false;
trySettingCacheState(queue.getRelativeUrl(), shard, QCacheState.Unavailable);
}
}
// add messages in the same order as messages list
boolean brokenJedis = false;
try {
for (CQSMessage message : messages) {
int delaySeconds = 0;
if (queue.getDelaySeconds() > 0) {
delaySeconds = queue.getDelaySeconds();
}
if (message.getAttributes().containsKey(CQSConstants.DELAY_SECONDS)) {
delaySeconds = Integer.parseInt(message.getAttributes().get(CQSConstants.DELAY_SECONDS));
}
String clientId = message.getSuppliedMessageId();
String messageId = message.getMessageId();
String memId = getMemQueueMessage(messageId);
if (cacheAvailable) {
try {
if (delaySeconds > 0) {
jedis.zadd(queue.getRelativeUrl() + "-" + shard + "-V", System.currentTimeMillis() + (delaySeconds * 1000), memId); //insert or update already existing
} else {
jedis.rpush(queue.getRelativeUrl() + "-" + shard + "-Q", memId);
}
} catch (JedisConnectionException e) {
trySettingCacheState(queue.getRelativeUrl(), shard, QCacheState.Unavailable);
}
logger.debug("event=send_message_batch cache_available=true msg_id= " + memId + " queue_url=" + queue.getAbsoluteUrl() + " shard=" + shard);