When using the WebJobs SDK what is the proper way to move a BrokeredMessage to the deadletter queue? Usually I would just call msg.DeadLetter(). However, the SDK takes care of managing the life cycle of the brokered message. It will call msg.Complete() if the method returns successful, and it will retry the message if an exception occurs. I need the 3rd case of telling the ServiceBus queue to move the message to the deadletter queue as it is a bad message.
You can explicitly deadletter the service bus queue and trigger a function when the message is dead lettered.
public static void ProcessSBQueueMessage(
[ServiceBusTrigger("inputqueue")] BrokeredMessage inputText)
{
inputText.DeadLetter("Webjobs", "webjobsdescription");
Console.WriteLine(inputText);
}
public static void ProcessSBDeadLetterQueueMessage(
[ServiceBusTrigger("inputqueue/$DeadLetterQueue")] BrokeredMessage inputText)
{
Console.WriteLine(inputText);
}
Related
I have the following code:
[FunctionName("myFunc")]
public static void Run([ServiceBusTrigger("myQueue", Connection = "ConnectionString")]string myQueueItem, ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
}
It is published in an Azure Function App that has Managed Identity configured to a namespace. The app shows no executions (no messages have been sent to the queue/namespace):
Yet, at the same time the namespace shows it has received requests:
The namespace has no other queues and NOTHING else connects/accesses/requests the namespace and queue. Also, if the function app is stopped the requests stop, as well.
I'm trying to figure out why would the function app send requests to the namespace (and so many) when it wasn't even triggered.
At least one reason that I can think of is that it could be monitoring the queue length.
Azure Functions will auto-scale up/down based on the number of messages in the queue after all.
We have a Service Bus Queue; we are thinking to handle messages through Service Bus Queue Trigger in the Azure Function. But we want to consume bulk messages (in a loop) instead of re-triggering Function App for each message. What should be the way to achieve this and by using which handler. Should Azure Function be only used or we can host an App Service for consuming the same.
You should use batches. Simply declare the variable as an array.
public static class ProcessOrders
{
[FunctionName("ProcessOrders")]
public static void Run(
[ServiceBusTrigger("orders", Connection = "ServiceBusConnection")]
Message[] orders, // <-- array
ILogger log)
{
log.LogInformation($"Number of orders: {orders.Length}");
}
}
You can further configure batch size and such using the host.json file.
this is how my azure function code looks like..
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("myqueue/$DeadLetterQueue", Connection = "ServiceBusConnection")]Message myQueueItem, ILogger log, int deliveryCount,
string messageId,
string deadLetterSource,
System.Collections.Generic.IDictionary<string, object> UserProperties
)
{}
I am able to get deadletter messages, but somehow not receiving regular messages from the service bus queue,
Is this expected behaviour?
if so how can i receive regular/deadletter messages in the same function.
I am using function 2.0 runtime.
Azure Function does not support receiving from more than a single source.
A queue and its dead-letter queue are considered two different queues.
You will need to have two Functions with some shared logic.
I have a basic QueueTrigger Azure function. When I disable the function in the azure portal it's still pulling messages off the storage queue (because when I look at the queue in the Azure Queue Storage Explorer the queue is empty and if i add a message it is immediately pulled off).
Here is the code:
[FunctionName("ProcessMessage")]
public static void Run([QueueTrigger("queue-name", Connection = "queue-connection")] Models.Message message, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {message}");
}
I noticed that when I stop the whole functions app it stops processing messages off the queue, but I was hoping that I could disable queue processing temporarily without stopping the whole function app. How does one do that?
Thanks!
Disabling the V1 function created in Visual Studio does not work in the azure portal. You should use the attribute:
https://learn.microsoft.com/en-us/azure/azure-functions/disable-function#functions-1x---c-class-libraries
(see important section)
I am using azure service bus topic and subscription mechanism and want to process the messages which are all in the dead letter queue.
Moreover i want to process the messages via azure web job in C# and send them back to queue. So i want to know how I can process the messages on the deadletter queue through my application?
When a message is deadlettered it goes onto the dead letter queue for the subscription from which it was read. You access that just like you'd access the original subscription except that you append /$DeadLetterQueue to the subscription name.
Moreover i want to process the messages via azure web job in C# and send them back to queue.
As spodger pointed that the path of your deadletter subscription would be:
{topic-path}/Subscriptions/{subcription-name}/$DeadLetterQueue
You could use the WebJobs SDK for Service Bus and leverage the ServiceBusTrigger to access your dead letter queue message(s) as follows:
public void ProcessDeadletterQueue(
[ServiceBusTrigger("topicName", "subscriptionName/$DeadLetterQueue")] BrokeredMessage message)
{
//TODO:
}
For more details, you could refer to here.
When a message is dead-lettered from a Service Bus Entity(Queue or Topic Subscription), it will be moved to the dead-letter path of the same entity. The reason for dead-lettering will be available in the message's custom properties DeadLetterReason and DeadLetterErrorDescription.
In order to receive the dead-letter messages,
string path = Microsoft.ServiceBus.Messaging.SubscriptionClient.FormatDeadLetterPath(topicPath, subscriptionName);
var subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, path);
BrokeredMessage message = subscriptionClient.Receive();