尽管将应用程序列入白名单,但具有防火墙规则的服务总线主题未触发 Azure 函数

问题描述 投票:0回答:1

由服务总线主题消息 v2 触发器触发的 Azure Function App(此处有相关文档

当服务总线上没有防火墙规则时,这可以正常工作,但是有了防火墙规则,即使将所有功能 IP 列入白名单,该功能也根本不会被触发(没有来自 sb 订阅的传递尝试,没有请求/登录功能)

我的触发点:

@app.function_name(name="consume_event")
@app.service_bus_topic_trigger(
    arg_name="message",
    topic_name=TOPIC_NAME,
    connection="SERVICE_BUS_CONN_STR", # App setting containing connection string of access policy of the topic
    subscription_name=SUBSCRIPTION_NAME
)
def consume_event(message: func.ServiceBusMessage):

TOPIC_NAME
SUBSCRIPTION_NAME
是带有各自资源名称的环境变量

"SERVICE_BUS_CONN_STR"
是包含连接字符串的环境变量(应用程序设置)的名称 - 这是在服务总线主题上创建的仅侦听访问密钥的主连接字符串

我在服务总线上列入白名单的 IP 是为我的 Function App 找到的所有 IP

我还在服务总线命名空间的网络部分启用了“允许受信任的 Microsoft 服务”

为什么功能还是没有被触发?

azure azure-functions azureservicebus firewall azure-servicebus-queues
1个回答
0
投票

我已按照以下步骤使用防火墙规则通过服务总线主题触发 Azure Function。

创建了服务总线主题触发器。

代码片段:

app = func.FunctionApp()
        
@app.service_bus_topic_trigger(arg_name="azservicebus", subscription_name="servicebussubscriptionName", topic_name="servicebustopicname",
                               connection="ServiceBusConnectionString") 
def servicebus_topic_trigger(azservicebus: func.ServiceBusMessage):
    logging.info('Python ServiceBus Topic trigger processed a message: %s',
                azservicebus.get_body().decode('utf-8'))

local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "ServiceBusConnectionString":"Service_Bus_Connection_String"
  }
}

ServiceBus=>Settings=>Networking
下启用选定的网络。

将客户端 IP 地址添加到防火墙部分下允许的地址列表中:

enter image description here

在服务总线主题中发送消息:

enter image description here

能够通过带有防火墙规则的Service Bus Topic触发该功能。

输出:

C:\Users\uname\pyfunc>func start
Found Python version 3.11.9 (py).

Azure Functions Core Tools
Core Tools Version:       4.0.6280 Commit hash: N/A +421f0144b42047aa289ce691dc6db4fc8b6143e6 (64-bit)
Function Runtime Version: 4.834.3.22875

[2024-11-15T10:12:18.276Z] Worker process started and initialized.

Functions:

        servicebus_topic_trigger: serviceBusTrigger

For detailed output, run func with --verbose flag.
[2024-11-15T10:12:23.192Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2024-11-15T10:12:57.965Z] Executing 'Functions.servicebus_topic_trigger' (Reason='(null)', Id=d4e52f60-cde4-4ec0-80b8-5c579a9bdbfe)
[2024-11-15T10:12:57.971Z] Trigger Details: MessageId: 26be26f0b96a47c3a8f3acba01a26069, SequenceNumber: 3, DeliveryCount: 1, EnqueuedTimeUtc: 2024-11-15T10:12:57.3740000+00:00, LockedUntilUtc: 2024-11-15T10:13:57.4050000+00:00, SessionId: (null)
[2024-11-15T10:12:58.233Z] Python ServiceBus Topic trigger processed a message: Welcome to Service Bus
[2024-11-15T10:12:58.346Z] Executed 'Functions.servicebus_topic_trigger' (Succeeded, Id=d4e52f60-cde4-4ec0-80b8-5c579a9bdbfe, Duration=404ms)

传送门:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.