if (!channels.containsKey(connection.getName())) {
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, connection.getName() + ": New channel available for distribution.");
}
try {
Channel chan = connection.getConnection().createChannel();
chan.queueDeclarePassive(amqpQueue);
channels.put(connection.getName(), chan);
} catch (IOException exc) {
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "Channel is not usable.", exc);
}
}
}
}
lastUpdate = now;
}
// Send the message
Iterator<Map.Entry<String, Channel>> iter = channels.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, Channel> entry = iter.next();
try {
Channel chan = entry.getValue();
String cnxName = entry.getKey();
if (!chan.isOpen()) {
iter.remove();
continue;
}
if (connectionNames != null && !connectionNames.contains(cnxName)) {
continue;
}
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "Sending message on " + cnxName);
}
chan.basicPublish("", amqpQueue, props, message.body);
channels.get(cnxName); // Access the used connection to update the LRU map
return;
} catch (IOException exc) {
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "Channel is not usable, remove from table.", exc);