001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq.broker.region.policy; 018 019import org.apache.activemq.ActiveMQMessageAudit; 020import org.apache.activemq.command.Message; 021import org.slf4j.Logger; 022import org.slf4j.LoggerFactory; 023 024/** 025 * A strategy for choosing which destination is used for dead letter queue 026 * messages. 027 * 028 */ 029public abstract class AbstractDeadLetterStrategy implements DeadLetterStrategy { 030 private static final Logger LOG = LoggerFactory.getLogger(AbstractDeadLetterStrategy.class); 031 private boolean processNonPersistent = false; 032 private boolean processExpired = true; 033 private boolean enableAudit = true; 034 private final ActiveMQMessageAudit messageAudit = new ActiveMQMessageAudit(); 035 036 @Override 037 public void rollback(Message message) { 038 if (message != null && this.enableAudit) { 039 messageAudit.rollback(message); 040 } 041 } 042 043 @Override 044 public boolean isSendToDeadLetterQueue(Message message) { 045 boolean result = false; 046 if (message != null) { 047 result = true; 048 if (enableAudit && messageAudit.isDuplicate(message)) { 049 result = false; 050 LOG.debug("Not adding duplicate to DLQ: {}, dest: {}", message.getMessageId(), message.getDestination()); 051 } 052 if (!message.isPersistent() && !processNonPersistent) { 053 result = false; 054 } 055 if (message.isExpired() && !processExpired) { 056 result = false; 057 } 058 } 059 return result; 060 } 061 062 /** 063 * @return the processExpired 064 */ 065 @Override 066 public boolean isProcessExpired() { 067 return this.processExpired; 068 } 069 070 /** 071 * @param processExpired the processExpired to set 072 */ 073 @Override 074 public void setProcessExpired(boolean processExpired) { 075 this.processExpired = processExpired; 076 } 077 078 /** 079 * @return the processNonPersistent 080 */ 081 @Override 082 public boolean isProcessNonPersistent() { 083 return this.processNonPersistent; 084 } 085 086 /** 087 * @param processNonPersistent the processNonPersistent to set 088 */ 089 @Override 090 public void setProcessNonPersistent(boolean processNonPersistent) { 091 this.processNonPersistent = processNonPersistent; 092 } 093 094 public boolean isEnableAudit() { 095 return enableAudit; 096 } 097 098 public void setEnableAudit(boolean enableAudit) { 099 this.enableAudit = enableAudit; 100 } 101}