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.camel.builder; 018 019import org.apache.camel.Endpoint; 020import org.apache.camel.ExchangePattern; 021import org.apache.camel.LoggingLevel; 022import org.apache.camel.Processor; 023import org.apache.camel.processor.FatalFallbackErrorHandler; 024import org.apache.camel.processor.SendProcessor; 025import org.apache.camel.processor.errorhandler.DeadLetterChannel; 026import org.apache.camel.spi.CamelLogger; 027import org.slf4j.LoggerFactory; 028 029/** 030 * A builder of a 031 * <a href="http://camel.apache.org/dead-letter-channel.html">Dead Letter 032 * Channel</a> 033 */ 034public class DeadLetterChannelBuilder extends DefaultErrorHandlerBuilder { 035 036 public DeadLetterChannelBuilder() { 037 // no-arg constructor used by Spring DSL 038 } 039 040 public DeadLetterChannelBuilder(Endpoint deadLetter) { 041 setDeadLetter(deadLetter); 042 // DLC do not log exhausted by default 043 getRedeliveryPolicy().setLogExhausted(false); 044 } 045 046 public DeadLetterChannelBuilder(String uri) { 047 setDeadLetterUri(uri); 048 } 049 050 @Override 051 public ErrorHandlerBuilder cloneBuilder() { 052 DeadLetterChannelBuilder answer = new DeadLetterChannelBuilder(); 053 super.cloneBuilder(answer); 054 return answer; 055 } 056 057 // Properties 058 // ------------------------------------------------------------------------- 059 060 @Override 061 public Processor getFailureProcessor() { 062 if (failureProcessor == null) { 063 // wrap in our special safe fallback error handler if sending to 064 // dead letter channel fails 065 Processor child = new SendProcessor(deadLetter, ExchangePattern.InOnly); 066 // force MEP to be InOnly so when sending to DLQ we would not expect 067 // a reply if the MEP was InOut 068 failureProcessor = new FatalFallbackErrorHandler(child, true); 069 } 070 return failureProcessor; 071 } 072 073 @Override 074 protected CamelLogger createLogger() { 075 return new CamelLogger(LoggerFactory.getLogger(DeadLetterChannel.class), LoggingLevel.ERROR); 076 } 077 078 @Override 079 public String toString() { 080 return "DeadLetterChannelBuilder(" + deadLetterUri + ")"; 081 } 082}