由于我是 azue 的初学者,我想知道以下过程应遵循的程序: 使用服务总线消息发送 xml,并使用逻辑应用接收和解析它。 谢谢
最佳答案
在本例中,我使用了 2 个逻辑应用,其中 1 个通过服务总线发送 XML 消息,另一个接收该消息。
逻辑应用流程 - 1(将 XML 消息发送到服务总线)
逻辑应用流程 - 2(从服务总线接收 XML 消息并解析)
您可以将 XML 转换为 JSON,然后使用 Parse_JSON 对其进行解析。
结果:
逻辑应用的代码 View - 1
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_message": {
"inputs": {
"body": {
"ContentData": "@{base64(outputs('XML_Content'))}",
"SessionId": "@{utcNow()}"
},
"host": {
"connection": {
"name": "@parameters('$connections')['servicebus']['connectionId']"
}
},
"method": "post",
"path": "/@{encodeURIComponent(encodeURIComponent('queue1'))}/messages"
},
"runAfter": {
"XML_Content": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"XML_Content": {
"inputs": "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>",
"runAfter": {},
"type": "Compose"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"servicebus": {
"connectionId": "/subscriptions/<SubId>/resourceGroups/<RG>/providers/Microsoft.Web/connections/servicebus-1",
"connectionName": "servicebus-1",
"id": "/subscriptions/<SubId>/providers/Microsoft.Web/locations/centralus/managedApis/servicebus"
}
}
}
}
}
逻辑应用的代码 View - 2
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@json(xml(base64ToString(triggerBody()?['ContentData'])))",
"runAfter": {},
"type": "Compose"
},
"Parse_JSON": {
"inputs": {
"content": "@outputs('Compose')",
"schema": {
"properties": {
"note": {
"properties": {
"body": {
"type": "string"
},
"from": {
"type": "string"
},
"heading": {
"type": "string"
},
"to": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_message_is_received_in_a_queue_(auto-complete)": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['servicebus_1']['connectionId']"
}
},
"method": "get",
"path": "/@{encodeURIComponent(encodeURIComponent('queue1'))}/messages/head",
"queries": {
"queueType": "Main"
}
},
"recurrence": {
"frequency": "Second",
"interval": 1
},
"type": "ApiConnection"
}
}
},
"parameters": {
"$connections": {
"value": {
"servicebus_1": {
"connectionId": "/subscriptions/<SubId>/resourceGroups/<RG>/providers/Microsoft.Web/connections/servicebus-2",
"connectionName": "servicebus-2",
"id": "/subscriptions/<SubId>/providers/Microsoft.Web/locations/centralus/managedApis/servicebus"
}
}
}
}
}
关于azure - 在消息服务总线中发送 XML 并在逻辑应用中解析它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73317041/