我正在使用 ADP 的 API 构建集成。已经有一个我将要使用的端点 - 这与 Azure 服务总线相关联。我知道主题名称,但我无法理解需要在 Azure 中创建的下一个工件。我希望传入的消息作为数据到达 EDW 或数据湖(它可能以 XML 格式出现,我可能需要将其转换为 azure sql 数据库):
我需要设计一个可扩展的解决方案 - 任何见解将不胜感激
谢谢
答案 0 :(得分:0)
您能否扩展此答案,或者是否有文档可以查看如何 将服务总线主题链接到 azure 函数,然后转储到数据中 湖?
我不知道你用的是什么语言,这里是用python实现的。
您可以使用服务总线触发器来监听来自服务总线队列或主题的消息。然后就可以使用数据湖SDK保存消息了:
使用azure function service bus trigger监听消息:
import logging
import azure.functions as func
def main(msg: func.ServiceBusMessage):
#put the logic of process the message here
logging.info('Python ServiceBus queue trigger processed message: %s',
msg.get_body().decode('utf-8'))
function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "msg",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "queuename",
"connection": "bowman1012_SERVICEBUS"
}
]
}
并使用如下代码将消息附加到数据湖:
from azure.storage.filedatalake import DataLakeServiceClient
connect_str = "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net"
datalake_service_client = DataLakeServiceClient.from_connection_string(connect_str)
myfilesystem = "test"
myfolder = "test"
myfile = "FileName.txt"
file_system_client = datalake_service_client.get_file_system_client(myfilesystem)
directory_client = file_system_client.create_directory(myfolder)
directory_client = file_system_client.get_directory_client(myfolder)
print("11111")
try:
file_client = directory_client.get_file_client(myfile)
file_client.get_file_properties().size
data = "Test2"
print("length of data is "+str(len(data)))
print("This is a test123")
filesize_previous = file_client.get_file_properties().size
print("length of currentfile is "+str(filesize_previous))
file_client.append_data(data, offset=filesize_previous, length=len(data))
file_client.flush_data(filesize_previous+len(data))
except:
file_client = directory_client.create_file(myfile)
data = "Test2"
print("length of data is "+str(len(data)))
print("This is a test")
filesize_previous = 0
print("length of currentfile is "+str(filesize_previous))
file_client.append_data(data, offset=filesize_previous, length=len(data))
file_client.flush_data(filesize_previous+len(data))
如果需要在本地开发azure函数,需要“azure函数核心工具”、“语言环境”、“VS Code和azure函数扩展”。
欲了解更多信息,请看这个:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python
这是数据湖SDK的API参考(在这个网页中你可以找到基于python和azure与各种服务交互的所有方法):