admin管理员组文章数量:1292285
I'm using Azure and Terraform to manage a Service Bus with three queues: A, B, and C. I want to trigger an Azure Function (in .NET) only when Queue A sends a message to the Dead-Letter Queue (DLQ). The function should execute some logic, such as sending an HTTP request to an API to notify the user about a failure.
Terraform Configuration (Simplified) Here’s a simplified version of my Terraform configuration:
resource "azurerm_servicebus_namespace" "servicebus_namespace" {
name = "sb-bwp-${var.environment}-${var.location}-001"
location = var.location
resource_group_name = azurerm_resource_group.resource_group.name
sku = var.environment == "prod" ? "Standard" : "Basic"
tags = merge(local.azure_common_tags, {
service = "network",
team = "backend"
})
}
resource "azurerm_servicebus_queue" "shared_servicebus_queue_a" {
name = "A"
namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id
partitioning_enabled = true
batched_operations_enabled = true
requires_session = false
requires_duplicate_detection = var.environment == "prod"
lock_duration = "PT1M"
duplicate_detection_history_time_window = "PT10M"
dead_lettering_on_message_expiration = false
}
resource "azurerm_servicebus_queue" "shared_servicebus_queue_b" {
name = "B"
namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id
partitioning_enabled = true
batched_operations_enabled = true
requires_session = false
requires_duplicate_detection = var.environment == "prod"
lock_duration = "PT1M"
duplicate_detection_history_time_window = "PT10M"
dead_lettering_on_message_expiration = false
}
resource "azurerm_servicebus_queue" "shared_servicebus_queue_c" {
name = "C"
namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id
partitioning_enabled = true
batched_operations_enabled = true
requires_session = false
requires_duplicate_detection = var.environment == "prod"
lock_duration = "PT1M"
duplicate_detection_history_time_window = "PT10M"
dead_lettering_on_message_expiration = false
}
My Questions: How can I configure an Azure Function to trigger only when Queue A's Dead-Letter Queue receives a message? What is the best practice for setting up this event-driven architecture using Terraform? Should I use an Event Grid Subscription, or is there a better approach for handling DLQ triggers? How can I ensure that messages from Queue B and Queue C do not trigger the function? If anyone has experience with this setup, I’d appreciate your insights!
I'm using Azure and Terraform to manage a Service Bus with three queues: A, B, and C. I want to trigger an Azure Function (in .NET) only when Queue A sends a message to the Dead-Letter Queue (DLQ). The function should execute some logic, such as sending an HTTP request to an API to notify the user about a failure.
Terraform Configuration (Simplified) Here’s a simplified version of my Terraform configuration:
resource "azurerm_servicebus_namespace" "servicebus_namespace" {
name = "sb-bwp-${var.environment}-${var.location}-001"
location = var.location
resource_group_name = azurerm_resource_group.resource_group.name
sku = var.environment == "prod" ? "Standard" : "Basic"
tags = merge(local.azure_common_tags, {
service = "network",
team = "backend"
})
}
resource "azurerm_servicebus_queue" "shared_servicebus_queue_a" {
name = "A"
namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id
partitioning_enabled = true
batched_operations_enabled = true
requires_session = false
requires_duplicate_detection = var.environment == "prod"
lock_duration = "PT1M"
duplicate_detection_history_time_window = "PT10M"
dead_lettering_on_message_expiration = false
}
resource "azurerm_servicebus_queue" "shared_servicebus_queue_b" {
name = "B"
namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id
partitioning_enabled = true
batched_operations_enabled = true
requires_session = false
requires_duplicate_detection = var.environment == "prod"
lock_duration = "PT1M"
duplicate_detection_history_time_window = "PT10M"
dead_lettering_on_message_expiration = false
}
resource "azurerm_servicebus_queue" "shared_servicebus_queue_c" {
name = "C"
namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id
partitioning_enabled = true
batched_operations_enabled = true
requires_session = false
requires_duplicate_detection = var.environment == "prod"
lock_duration = "PT1M"
duplicate_detection_history_time_window = "PT10M"
dead_lettering_on_message_expiration = false
}
My Questions: How can I configure an Azure Function to trigger only when Queue A's Dead-Letter Queue receives a message? What is the best practice for setting up this event-driven architecture using Terraform? Should I use an Event Grid Subscription, or is there a better approach for handling DLQ triggers? How can I ensure that messages from Queue B and Queue C do not trigger the function? If anyone has experience with this setup, I’d appreciate your insights!
Share asked Feb 13 at 10:54 Tiago FerreiraTiago Ferreira 111 bronze badge 02 Answers
Reset to default 1You can create a Service Bus trigger for a dead-lettered queue the same way you make it for the active messages queue. We use this on a daily basis to manage the failed messages.
This is part of the function code and besides the app settings there is nothing specific regarding the deployment (no matter what tool you use).
Here is an example for a trigger in C#:
[Function("ServiceBusDeadLetter")]
public async Task RunServiceBusDeadLetterAsync(
[ServiceBusTrigger("%ServiceBus.TopiName%", "%ServiceBus.SubscriptionName%" + "/$deadletterqueue", Connection = "ServiceBus.Connection")]
ServiceBusReceivedMessage message, FunctionContext context, ServiceBusMessageActions messageActions)
{
//do the job
}
There not a dead letter trigger that I am aware of, but you could poll. This will sound a bit strange and there are other alternative,
- Create logic app to send poll message to an new queue, say every min
- Trigger Azure Function on that new queue
- The new function polls the dead letter for the first queue.
Its crude and not ideal
本文标签:
版权声明:本文标题:.net - How to Trigger an Azure Function When a Specific Service Bus Queue Sends a Message to the Dead-Letter Queue? - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741547164a2384659.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论