protected AbstractMessageListenerContainer(IApplicationContext applicationContext, IConnectionFactory connectionFactory, string name = null, ILoggerFactory loggerFactory = null) { _loggerFactory = loggerFactory; _logger = _loggerFactory?.CreateLogger(GetType()); ApplicationContext = applicationContext; ConnectionFactory = connectionFactory; ErrorHandler = new ConditionalRejectingErrorHandler(_logger); MessageHeadersConverter = new DefaultMessageHeadersConverter(_logger); ExclusiveConsumerExceptionLogger = new DefaultExclusiveConsumerLogger(); BatchingStrategy = new SimpleBatchingStrategy(0, 0, 0L); TransactionAttribute = new DefaultTransactionAttribute(); ServiceName = name ?? GetType().Name + "@" + GetHashCode(); }
public void TestFatalsAreRejected() { var handler = new ConditionalRejectingErrorHandler(); handler.HandleError(new ListenerExecutionFailedException("intended", new InvalidOperationException(), Message.Create(Encoding.UTF8.GetBytes(string.Empty)))); Assert.Throws <RabbitRejectAndDontRequeueException>( () => handler.HandleError(new ListenerExecutionFailedException("intended", new MessageConversionException(string.Empty), Message.Create(Encoding.UTF8.GetBytes(string.Empty))))); var message = Message.Create(Encoding.UTF8.GetBytes(string.Empty)); var parmInfo = new Moq.Mock <ParameterInfo>(); parmInfo.Setup(p => p.Position).Returns(1); parmInfo.Setup(p => p.Member.ToString()).Returns("testMember"); Assert.Throws <RabbitRejectAndDontRequeueException>( () => handler.HandleError(new ListenerExecutionFailedException("intended", new MethodArgumentTypeMismatchException(message, parmInfo.Object, string.Empty), message))); Assert.Throws <RabbitRejectAndDontRequeueException>( () => handler.HandleError(new ListenerExecutionFailedException("intended", new MethodArgumentNotValidException(message, parmInfo.Object, string.Empty), message))); }
private void DoTest(Exception cause) { var handler = new ConditionalRejectingErrorHandler(); handler.HandleError(new ListenerExecutionFailedException("test", cause, Message.Create(Array.Empty <byte>()))); }