Microsoft.Azure.ServiceBus Microsoft.Azure.ServiceBus Microsoft.Azure.ServiceBus.Core System.Threading.Tasks Microsoft.Azure.ServiceBus.Management async Task Main() { var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString"); var src = "src"; var dest = "dst"; await Initiate(connectionString, src, dest); var connection = new ServiceBusConnection(connectionString); var queueClient = new QueueClient(connection, src, ReceiveMode.PeekLock, RetryPolicy.Default); var sender = new MessageSender(connection, dest, src); var counter = 1; queueClient.RegisterMessageHandler(async (message, token) => { $"received {message.MessageId}".Dump(); using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionScopeAsyncFlowOption.Enabled)) { await sender.SendAsync(new Message()); $"sent".Dump(); await queueClient.CompleteAsync(message.SystemProperties.LockToken); scope.Complete(); } }, new MessageHandlerOptions(exceptionArgs => { exceptionArgs.Dump(); //$"failuer happened {counter++} times. Exception: {exceptionArgs.Exception.Message}".Dump(); return Task.CompletedTask; }) { AutoComplete = false, MaxConcurrentCalls = 1 }); Console.WriteLine("Press enter to exit"); Util.ReadLine(); } async Task Initiate(string connectionString, string src, string dest) { var client = new ManagementClient(connectionString); await Task.WhenAll(execute(src), execute(dest)); await client.CloseAsync(); async Task execute(string queueName) { if (await client.QueueExistsAsync(queueName)) { await client.DeleteQueueAsync(queueName); } await client.CreateQueueAsync(new QueueDescription(queueName) { MaxDeliveryCount = 100, LockDuration = TimeSpan.FromMinutes(5) }); } }