1

I have azure webjob setup using next code:

Program.cs:

public class Program {
    static void Main(){
        JobHostConfiguration config = new JobHostConfiguration();
        config.Tracing.ConsoleLevel = TraceLevel.Verbose;
        config.Queues.BatchSize = 1;
        config.UseTimers();
        config.Queues.MaxDequeueCount = 1;
        config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(3);
        ServiceBusConfiguration sbConfig = new ServiceBusConfiguration();
        sbConfig.MessageOptions = new OnMessageOptions
        {
            MaxConcurrentCalls = 5,
            AutoRenewTimeout = TimeSpan.FromMinutes(10),
            AutoComplete = true
        };

        config.UseServiceBus(sbConfig);
        config.NameResolver = new QueueNameResolver();

        var host = new JobHost(config);
        host.RunAndBlock();
    }

    public class QueueNameResolver : INameResolver
    {
        public string Resolve(string name)
        {
            return ConfigurationManager.AppSettings[name];
        }
    }
}

Functions.cs

public static void ProcessQueueMessage([ServiceBusTrigger("%WebjobIncomingQueueName%")] ProcessingInfo processingInfo, TextWriter webjobTextWriter){
    webjobTextWriter.WriteLine("Service Bus trigger started");
    //long running task simulation
    Thread.Sleep(400000);
}

App.config file queue name configuration section:

<appSettings>
    <add key="WebjobIncomingQueueName" value="webjob-test" />
</appSettings>

ProcessingInfo class:

 public class ProcessingInfo {
        public long ID { get; set; }
 }

The problem here is that for the same message from webjob-test queue ProcessQueueMessage is triggered each minute after the first occurrence. According to answer here this should be easily configured using OnMessageOptions.AutoRenewTimeout, however it doesn't seems to be working. Can someone please help with this issue?

Community
  • 1
  • 1
Volodymyr
  • 1,209
  • 1
  • 15
  • 26
  • The [documentation](https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.onmessageoptions.aspx), talks about the 60 second timeout, and describes how to increase it. This is for the OnMessageOptions class, but I can't see how it relates to WebJobs. – lxalln Apr 28 '16 at 09:39
  • @Vova. After configuring the timeout is it still triggering the same message every minute? The only reason I can think of is that the processing function is taking more time than the timeout because of which the SDK is assuming that the message is not yet processed and hence it is adding it back to the queue. Is it possible to move the processing to a back ground thread? – Sandesh May 13 '16 at 07:33

2 Answers2

0

When you say to the message that is complated, then will not be back in the queue Example

while ((message = myQueueClient.Receive(new TimeSpan(hours: 0, minutes: 0, seconds: 5))) != null)
{
    Console.WriteLine(string.Format("Message received: {0}, {1}, {2}", message.SequenceNumber, message.Label, message.MessageId));
    message.Complete();

    Console.WriteLine("Processing message (sleeping...)");
    Thread.Sleep(1000);
}

Check the link for more information

Lyubomir Velchev
  • 962
  • 2
  • 11
  • 30
0

This could happen when the message is poisonuouse and then the WebJob SDK does not delete it.

Messages whose content causes a function to fail are called poison messages. When the function fails, the queue message is not deleted and eventually is picked up again, causing the cycle to be repeated. The SDK can automatically interrupt the cycle after a limited number of iterations, or you can do it manually.

See: https://learn.microsoft.com/en-us/azure/app-service-web/websites-dotnet-webjobs-sdk-storage-queues-how-to#a-idpoisona-how-to-handle-poison-messages

Ravit D
  • 907
  • 9
  • 27