-1

I've created an azure web job which gets trigger on service bus queue messages. When i run the web job it processes the messages from the service bus queue, som my simple question is as follows;

Is there a way to make the web job just trigger on the new message delivered to the queue without processing it rendering the message complete and removed from the queue?

I am currently using "Servicebustrigger" to trigger the queue in my function class.

public void Processservicebus([ServiceBusTrigger("%Values:QueueName%", AutoCompleteMessages = false, Connection = "ServiceBusConnection")] string myQueueItem, ILogger log)
{
    log.LogInformation(myQueueItem);
    var testGetConfig = _configuration.GetValue<string>("Values:QueueName");
}
H4p7ic
  • 1,669
  • 2
  • 32
  • 61
  • It should already do that since you set `AutoCompleteMessages` to false – Peter Bons Sep 02 '22 at 08:32
  • Yeah i had the same understanding as you to be honest, hens the question. I can add that I've looked around to if there are any other functionalities that use the same queue but again i didn't find any. that would have been the logical answer though. – H4p7ic Sep 02 '22 at 11:12

1 Answers1

1

A function triggered by the Service Bus message will process a message. That's what it's designed for. Wherever configured to auto-complete or not, messages will be either gone from the queue (completed) or dead-lettered (auto-completion turned off) after N number of processing attempts specified by the queue's MaxDeliveryCount setting.

For what your asking for, pure notification about messages existence and processing by something other than function, you'll need to review your design.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • Thanks for your respons, then what would a design like that be? What triggertype reacts on messages exsistance in servicebus queues? Should i manually abondon the message at the end of my webjob process for example? – H4p7ic Sep 02 '22 at 13:58
  • Triggers are intended to kick off functions execution to process the data coming in. Unlike Azure Event Grid, which is designed to create notifications. So even if you'd abandon the message, it would keep coming until dead-lettered, just as I've described in the answer. You'll have to review what you're trying to achieve because if another process needs to handle the messages, you have a competing consumer scenario where consumers are not the same logical scaled-out consumer. And that's asking for trouble. 1/2 – Sean Feldman Sep 02 '22 at 17:08
  • Alternatives would be [Event Grid](https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-to-event-grid-integration-concept), a Timer trigger that checks for new messages, or a custom background process peeking for messages and then processing those. It depends on what you're trying to accomplish from a process point of view rather than technical. Which wasn't shared. 2/2 – Sean Feldman Sep 02 '22 at 17:09
  • Ok, i understand, well in short process wise, we're looking to create a simple notifier, that is if an message lands on the queue the web job will trigger and send a notification to another system telling it there are new messages in the queue. That said i think we looked into Event Grid but wanted to go the web job route. – H4p7ic Sep 05 '22 at 06:52
  • 1
    What's the rationale for having a notification about messages available for processing? What's the reason the intermediate step is needed to begin with? What is the issue with processing messages as they become available, skipping the notification part altogether? – Sean Feldman Sep 05 '22 at 18:52
  • Well its an temporary transitioning solution made to notify a legacy system that can not process the messages on reaction, the external system have to get a notification in which the messages to be processed needs to be scheduled before processing. hens the notification requirement. – H4p7ic Sep 09 '22 at 12:12
  • 1
    I see. In that case the processor is **not** the function. Therefore ASB trigger cannot be used. I'd look into a timer trigger that periodically looks at the message count and generates a notification for the legacy system. Cheers. – Sean Feldman Sep 09 '22 at 13:10
  • Yupp, that seems to be the most logical solution for the time being. This was in any case enlightening. Thank you for your Answers Sean! :) – H4p7ic Sep 12 '22 at 07:55