我有一个带有队列触发器的 Java 11 Azure 函数,该函数在部署到 Azure 时按预期工作,并正确从定义的服务总线主题中提取消息。但是,运行相同的功能locally除非我回滚版本,否则不起作用Azure Functions 绑定扩展 https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-register。如果我不恢复版本,该函数将在本地启动,但永远不会从服务总线主题中提取消息。
变量是host.json
项目中定义扩展包版本的文件。对于部署到 Azure 的函数,如下host.json
使用为最新版本的扩展包配置的文件:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.3.0, 4.0.0)"
}
}
本地运行的版本是这样的:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
Azure 函数本身并没有做任何特殊的事情。在函数中设置断点时,如果我不将扩展包版本恢复到 2/3 版本,则永远不会调用它。
public class QueueTrigger {
private DatabaseProvider database;
@FunctionName(Constants.FunctionNames.RUN_CHANGE_HISTORY_TRIGGER)
public void run(
@ServiceBusTopicTrigger(name = "msg",
topicName = "%SERVICE_BUS_TOPIC_NAME%",
subscriptionName = "%SERVICE_BUS_SUBSCRIPTION_NAME%",
connection = "ServiceBusConnection") String message,
final ExecutionContext context) {
Logger logger = context.getLogger();
try {
logger.log(Level.INFO, String.format("Queue Trigger START (%s)", message));
database = new CosmosDatabaseProvider(logger);
ChangeHistoryService service = new ChangeHistoryService(database, logger);
service.processChanges(message);
this.database.close();
logger.log(Level.INFO, "Queue Trigger DONE");
} catch (Exception ex) {
logger.log(Level.SEVERE, ex.getMessage());
throw new ServiceResponseException(ex.getMessage(), ex);
}
}
}
我有Azure 函数核心工具 https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=v4%2Cwindows%2Ccsharp%2Cportal%2Cbash%2Ckedav4.0.3971(最新版本)安装在我的电脑上,我的其他团队成员也有同样的问题。
我的本地环境中缺少什么,导致最新版本的扩展包无法工作?