简体   繁体   English

Azure 与服务总线主题集成

[英]Azure intergration with service bus topic

I am building an integration using API's from ADP.我正在使用 ADP 的 API 构建集成。 There is already an endpoint that I will be using - this is tied to a azure service bus.我将使用一个端点——它与 azure 服务总线相关联。 I have the name of the topic but I'm having trouble understanding the next artifacts that need to be created in Azure.我知道该主题的名称,但我无法理解需要在 Azure 中创建的下一个工件。 I want the incoming messages to hit an EDW or just the data lake as data (it might be coming in as XML format, which I may need to convert to azure sql database):我希望传入的消息到达 EDW 或只是数据湖作为数据(它可能以 XML 格式出现,我可能需要将其转换为 azure sql 数据库)

  • Should I create another subscription tied to the EDW that can pick up the messages from the service bus topic?我是否应该创建另一个与 EDW 绑定的订阅,以便从服务总线主题中获取消息? (I have not attempted this before) (我以前没有尝试过)
  • Or Should I create a logic app to directly read the service bus or service bus topic?或者我应该创建一个逻辑应用程序来直接读取服务总线或服务总线主题吗? (I have not attempted this either) (我也没有尝试过)

I need to design a scalable solution - any insight would be greatly appreciated我需要设计一个可扩展的解决方案 - 任何见解将不胜感激

Thanks谢谢

can you expand on this answer or is there documentation to see how to linked the service bus topic to azure function then dump into data lake?您可以扩展此答案还是有文档可以查看如何将服务总线主题链接到 azure function 然后转储到数据湖中?

I'm not sure what language you use, here is implemented in python.我不确定你使用的是什么语言,这里是在 python 中实现的。

You can use a service bus trigger to listen the messages come in of the service bus queue or topic.您可以使用服务总线触发器来侦听来自服务总线队列或主题的消息。 Then you can use data lake SDK to save the message:然后您可以使用数据湖 SDK 来保存消息:

Use azure function service bus trigger to listen the message:使用 azure function 服务总线触发器监听消息:

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"
    }
  ]
}

And use code like below to append messages to data lake:并使用如下代码将 append 消息发送到数据湖:

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))

If you need to develop azure function on local, you need 'azure function core tools','language environment','VS Code and azure function extension'. If you need to develop azure function on local, you need 'azure function core tools','language environment','VS Code and azure function extension'.

For more information, please have a look of this:有关更多信息,请查看以下内容:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=python https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=python

And this is the API reference of data lake SDK(In this web page you can find all the methods of interacting with various services based on python and azure):这是数据湖 SDK 的 API 参考(在此 web 页面中,您可以找到与基于 python 和 azure 的各种服务交互的所有方法):

https://docs.microsoft.com/en-us/python/api/azure-storage-file-datalake/azure.storage.filedatalake.datalakeserviceclient?view=azure-python https://docs.microsoft.com/en-us/python/api/azure-storage-file-datalake/azure.storage.filedatalake.datalakeserviceclient?view=azure-python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM