【Azure 应用服务】部署Kafka Trigger Function到Azure Function服务中,解决自定义域名解析难题

简介: 【Azure 应用服务】部署Kafka Trigger Function到Azure Function服务中,解决自定义域名解析难题

问题描述

经过前两篇文章,分别使用VM搭建了Kafka服务,创建了Azure Function项目,并且都在本地运行成功。

  1. 【Azure Developer】在Azure VM (Windows) 中搭建 kafka服务,并且通过本地以及远程验证 发送+消费 消息
  2. 【Azure 应用服务】本地创建Azure Function Kafka Trigger 函数和Kafka output的HTTP Trigger函数实验

现在,本文中将把Kafka Trigger Function代码部署到Azure中,并解决Function在云上运行时遇见的 (Failed to resolve 'xxxxxxtest01.c2vbkl4ntjrehlqe5jmwliuhob.bx.internal.chinacloudapp.cn:9092': No such host is known. )问题

 

问题解答

第一部分:从VS 2022中部署Function代码到Azure Function App

首先:在Azure中创建好一个Function App,在Function App Overview页面下载Publish Profile文件

然后:在VS 2022中引入Publish Profile文件,点击发布

最后:把 BrokerList ,KafkaPassword ,ConnectionString 添加到Function App的Application Setting中

"BrokerList": "xxx.xxx.xxx.xxx:9092",

   "KafkaPassword": "KafkaPassword",

   "ConnectionString": "ConnectionString"

以上操作完成后,正常情况Function会运行成功。但是由于实验中使用的Kafka服务没有公共域名,只是使用IP地址进行访问。但是Kafka Trigger作为消费者连接到服务端时,GroupCoordinator 会通过IP地址,获取到Kafka Server生产的默认域名(如:Failed to resolve 'xxxxxxtest01.c2vbkl4ntjrehlqe5jmwliuhob.bx.internal.chinacloudapp.cn:9092': No such host is known.)然后需要在本地进行解析,而VM环境中可以通过修改 windows host文件来指定IP。但是在PaaS服务(Azure Function)中,是无法修改的。那么是否有办法来自定义DNS服务器呢? 请见第二部分。

 

 

第二部分:解决Failed to resolve 'xxxxxxtest01.c2vbkl4ntjrehlqe5jmwliuhob.bx.internal.chinacloudapp.cn:9092': No such host is known. 问题

为了能够让Azure Function能够解析 *****.c2vbkl4ntjrehlqe5jmwliuhob.bx.internal.chinacloudapp.cn 的私有域名,就需要找一个自定义的DNS服务器,然后在Function中配置  WEBSITE_DNS_SERVER,用指定的DNS 服务器来解析私有域名。

 

本文中使用的自定义DNS服务为 Azure 的 DNS Zone 服务,它可以自由的定义私有域名并且指定A记录。

第一步: 以 bx.internal.chinacloudapp.cn为 自定义域创建DNS Zone

进入DNS zones - Microsoft Azure 由世纪互联运营,创建名为 bx.internal.chinacloudapp.cn的DNS Zone资源

第二步:把kafka服务器的默认域名在DNS Zone中添加为A记录

点击“Record Set”,选择A记录,输入kafka服务域名,然后添加IP地址。

第三步:通过ping指令反解析处DNS Zone的Service IP地址,然后以此IP地址测试解析 Kafka域名,验证是否能成功解析为Kafka服务IP地址

通过 nslookup 指定DSN解析服务器为 ns1-02.azure-dns.cn 成功解析kafka域名, 因为Azure Funciton WEBSITE_DNS_SERVER  只能设置为IP地址,所以需要找出ns1-02.azure-dns.cn的IP地址

第四步:把DNS Zone服务的IP地址作为Function 的第一DNS解析服务器

在Funciton App 的配置页面,设置 WEBSITE_DNS_SERVER 和WEBSITE_ALT_DNS_SERVER 的值。

WEBSITE_DNS_SERVER  40.73.192.2
WEBSITE_ALT_DNS_SERVER  168.63.129.16  

PS: WEBSITE_ALT_DNS_SERVER 作为次DNS服务器, 它的值为168.63.129.16 (Azure服务默认的DNS服务器地址)

第五步:在Function1, Function2中,验证Function运行正常

 

 

 

【END】

相关文章
|
4月前
|
API C++
【Azure 环境】VS Code登录China Azure(Function)报错 An error occurred while signing in: invalid_request - AADSTS65002
An error occurred while signing in: invalid_request - AADSTS65002: Consent between first party application 'c27c220f-ce2f-4904-927d-333864217eeb' and first party resource '797f4846-ba00-4fd7-ba43-dac1f8f63013' must be configured via preauthorization - applications owned and operated by Microsoft mus
235 13
|
8月前
|
存储 安全 数据安全/隐私保护
【Azure Function App】在Function App中使用System Managed Identity访问Storage Account
本文介绍了如何在Azure Function中使用托管身份(Managed Identity)替代AzureWebJobsStorage连接函数应用到存储账户,以提高安全性并减少Access Key的使用。具体步骤包括:1) 启用系统分配的身份;2) 为函数应用授予存储访问权限,添加必要角色(如Storage Blob Data Contributor);3) 配置`AzureWebJobsStorage__blobServiceUri`参数指定Blob Service Uri。完成后删除旧配置,即可通过Managed Identity访问Storage Account。
257 20
|
3月前
|
数据安全/隐私保护
【Azure Function App】PowerShell Function 执行 Get-AzAccessToken 的返回值类型问题:System.String 与 System.Security.SecureString
将PowerShell Function部署到Azure Function App后,Get-AzAccessToken返回值类型在不同环境中有差异。正常为SecureString类型,但部分情况下为System.String类型,导致后续处理出错。解决方法是在profile.ps1中设置环境变量$env:AZUREPS_OUTPUT_PLAINTEXT_AZACCESSTOKEN=false,以禁用明文输出。
118 0
|
4月前
|
JSON 数据格式
【Azure 环境】当一个Azure Function资源创建很久了,是否可以获取到它的创建时间呢?
用户在尝试获取 Azure Function App 的创建时间时发现,资源 JSON 中缺少 `createdTime` 字段,仅能查看到 `lastModifiedTime`。同时,活动日志和 Azure Resource Graph 查询也未能提供创建时间信息。经解答,Azure 并未为所有资源类型记录创建时间,建议在部署时将创建时间作为标签记录。若创建时间在 90 天内,可通过部署日志间接获取。
196 7
|
5月前
|
网络协议 API 网络安全
【Azure Function App】发现部分请求Function App遇见 403.72 报错(请求Body>100KB)
在调用Azure Function的HTTP Trigger时,发送POST请求偶尔出现403错误,且响应为空、Header信息少。经排查发现,当请求Body大于100KB时会触发403.72错误,原因是启用了“Client Certificate mode”为“Optional Interactive User”。解决方法是将该模式设置为“Ignore”。由于TLS重新协商机制限制,大请求体无法正常处理,导致此问题。
190 2
|
7月前
|
安全 Linux 开发工具
【Azure Function】分享把Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤
本文介绍了将Azure Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤。.NET 6.0作为长期支持版本,生命周期至2024年11月结束。为确保持续支持,建议升级至更新版本。升级步骤包括安装.NET 8 SDK、更新Azure Functions Core Tools、修改项目文件目标框架为net8.0、更新兼容的NuGet包、本地测试以及重新发布到Azure。更多详细信息可参考官方文档。
348 9
|
11月前
|
C#
【Azure Function】Function App出现System.IO.FileNotFoundException异常
Exception while executing function: xxxxxxx,The type initializer for 'xxxxxx.Storage.Adls2.StoreDataLakeGen2Reading' threw an exception. Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the
278 64
|
10月前
|
消息中间件 Java Kafka
【Azure Kafka】使用Spring Cloud Stream Binder Kafka 发送并接收 Event Hub 消息及解决并发报错
reactor.core.publisher.Sinks$EmissionException: Spec. Rule 1.3 - onSubscribe, onNext, onError and onComplete signaled to a Subscriber MUST be signaled serially.
190 5
|
10月前
|
JavaScript API
【Azure Function】Function App门户上的Test/Run返回错误:Failed to fetch
Running your function in portal requires the app to explicitly accept requests from https://portal.azure.cn. This is known as cross-origin resource sharing (CORS).Configure CORS to add https://portal.azure.cn to allowed origins.
267 7

热门文章

最新文章

推荐镜像

更多
  • DNS