ensure exception is logged if one is raised sending a message to a dead letter queue

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@569270 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2007-08-24 06:29:18 +00:00
parent 5a5056e73b
commit 3cd1e6c73f
1 changed files with 42 additions and 32 deletions

View File

@ -636,38 +636,48 @@ public class RegionBroker implements Broker {
getRoot().sendToDeadLetterQueue(context, node); getRoot().sendToDeadLetterQueue(context, node);
} }
public void sendToDeadLetterQueue(ConnectionContext context, MessageReference node) { public void sendToDeadLetterQueue(ConnectionContext context,
try { MessageReference node){
if (node != null) { try{
Message message = node.getMessage(); boolean sent=false;
if (message != null) { if(node!=null){
DeadLetterStrategy deadLetterStrategy = node.getRegionDestination().getDeadLetterStrategy(); Message message=node.getMessage();
if (deadLetterStrategy != null) { if(message!=null&&node.getRegionDestination()!=null){
if (deadLetterStrategy.isSendToDeadLetterQueue(message)) { DeadLetterStrategy deadLetterStrategy=node
long expiration = message.getExpiration(); .getRegionDestination().getDeadLetterStrategy();
message.setExpiration(0); if(deadLetterStrategy!=null){
message.setProperty("originalExpiration", new Long(expiration)); if(deadLetterStrategy.isSendToDeadLetterQueue(message)){
if (!message.isPersistent()) { long expiration=message.getExpiration();
message.setPersistent(true); message.setExpiration(0);
message.setProperty("originalDeliveryMode", "NON_PERSISTENT"); message.setProperty("originalExpiration",new Long(
} expiration));
// The original destination and transaction id do if(!message.isPersistent()){
// not get filled when the message is first message.setPersistent(true);
// sent, message.setProperty("originalDeliveryMode",
// it is only populated if the message is routed to "NON_PERSISTENT");
// another destination like the DLQ }
ActiveMQDestination deadLetterDestination = deadLetterStrategy.getDeadLetterQueueFor(message.getDestination()); // The original destination and transaction id do
BrokerSupport.resend(context, message, deadLetterDestination); // not get filled when the message is first
} // sent,
} // it is only populated if the message is routed to
} else { // another destination like the DLQ
LOG.warn("Null message for node: " + node); ActiveMQDestination deadLetterDestination=deadLetterStrategy
} .getDeadLetterQueueFor(message
} .getDestination());
} catch (Exception e) { BrokerSupport.resend(context,message,
LOG.warn("Failed to pass expired message to dead letter queue"); deadLetterDestination);
} sent=true;
} }
}
}
}
if(sent==false){
LOG.warn("Failed to send "+node+" to dead letter queue");
}
}catch(Exception e){
LOG.warn("Failed to pass expired message to dead letter queue",e);
}
}
public Broker getRoot() { public Broker getRoot() {
try { try {