public async Task Should_Publish_Message_On_Error_Exchange_If_Subscribe_Throws_Exception() { /* Setup */ var conventions = new NamingConventions(); using (var client = TestClientFactory.CreateNormal(ioc => ioc.AddSingleton(c => conventions))) { var recieveTcs = new TaskCompletionSource <HandlerExceptionMessage>(); MessageContext firstRecieved = null; MessageContext secondRecieved = null; client.SubscribeAsync <HandlerExceptionMessage>((message, context) => { secondRecieved = context; recieveTcs.TrySetResult(message); return(Task.FromResult(true)); }, c => c .WithExchange(e => e .WithName(conventions.ErrorExchangeNamingConvention()) .WithDurability(false)) .WithQueue(q => q.WithArgument(QueueArgument.MessageTtl, (int)TimeSpan.FromSeconds(1).TotalMilliseconds).WithAutoDelete()) .WithRoutingKey("#")); client.SubscribeAsync <BasicMessage>((message, context) => { firstRecieved = context; throw new Exception("Oh oh!"); }); var originalMsg = new BasicMessage { Prop = "Hello, world" }; /* Test */ client.PublishAsync(originalMsg); await recieveTcs.Task; /* Assert */ Assert.Equal(((BasicMessage)recieveTcs.Task.Result.Message).Prop, originalMsg.Prop); Assert.NotNull(firstRecieved); Assert.NotNull(secondRecieved); Assert.Equal(firstRecieved.GlobalRequestId, secondRecieved.GlobalRequestId); } }