Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

Max retry count not working in retryexponential class

$
0
0

            ServiceBusConnectionStringBuilder connBuilder = new ServiceBusConnectionStringBuilder();
            connBuilder.ManagementPort = HttpPort;
            connBuilder.RuntimePort = TcpPort;
            connBuilder.Endpoints.Add(new UriBuilder() { Scheme = "sb", Host = ServerFQDN, Path = ServiceNamespace }.Uri);
            connBuilder.StsEndpoints.Add(new UriBuilder() { Scheme = "https", Host = ServerFQDN, Port = HttpPort, Path = ServiceNamespace }.Uri);
            MessagingFactory messageFactory = MessagingFactory.CreateFromConnectionString(connBuilder.ToString());
            NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(connBuilder.ToString());
            messageFactory.RetryPolicy =
           new RetryExponential(
               minBackoff: TimeSpan.FromSeconds(0),
               maxBackoff: TimeSpan.FromSeconds(30),
                 deltaBackoff: TimeSpan.FromSeconds(3), terminationTimeBuffer: TimeSpan.FromSeconds(3),
               maxRetryCount: 3);
            namespaceManager.CreateSubscription("NewTopic", subscriberId);
            namespaceManager.Settings.RetryPolicy =
               new RetryExponential(
                   minBackoff: TimeSpan.FromSeconds(0),
                   maxBackoff: TimeSpan.FromSeconds(30),
                     deltaBackoff: TimeSpan.FromSeconds(3), terminationTimeBuffer: TimeSpan.FromSeconds(3),
                   maxRetryCount: 3);
            SubscriptionClient receiver = messageFactory.CreateSubscriptionClient("NewTopic", subscriberId);

            try
            {
                OnMessageOptions options = new OnMessageOptions();
                options.AutoComplete = false; 
                options.ExceptionReceived += options_ExceptionReceived;
                receiver.RetryPolicy =
new RetryExponential(
   minBackoff: TimeSpan.FromSeconds(0),
   maxBackoff: TimeSpan.FromSeconds(30),
     deltaBackoff: TimeSpan.FromSeconds(3), terminationTimeBuffer: TimeSpan.FromSeconds(3),
   maxRetryCount: 3);
                receiver.OnMessage(receivedMessage =>
                {
                    try
                    {

                        Console.WriteLine(receivedMessage.Label);

                        bool t = receivedMessage.IsBodyConsumed;
                        Console.WriteLine(string.Format("Message received: {0}", receivedMessage.GetBody<string>()));
                        Console.WriteLine(receivedMessage.SequenceNumber);
                        Console.WriteLine(receivedMessage.TimeToLive);
                        Console.WriteLine(receivedMessage.To);

                        Console.WriteLine(receivedMessage.DeliveryCount);



                        receivedMessage.Abandon();
                    }
                    catch (Exception)
                    {
                        // Indicates a problem, unlock message in subscription.
                        receivedMessage.Abandon();
                    }
                }, options);

I am Abandoning the message after i receive and i set maxRetryCountas 3. But it's delivering the message 10 times

                          

Viewing all articles
Browse latest Browse all 1916

Trending Articles