azure - 在消息服务总线中发送 XML 并在逻辑应用中解析它

标签 azure azure-logic-apps azureservicebus

由于我是 azue 的初学者,我想知道以下过程应遵循的程序: 使用服务总线消息发送 xml,并使用逻辑应用接收和解析它。 谢谢

最佳答案

在本例中,我使用了 2 个逻辑应用,其中 1 个通过服务总线发送 XML 消息,另一个接收该消息。

逻辑应用流程 - 1(将 XML 消息发送到服务总线)

enter image description here

逻辑应用流程 - 2(从服务总线接收 XML 消息并解析)

您可以将 XML 转换为 JSON,然后使用 Parse_JSON 对其进行解析。

enter image description here

结果:

enter image description here

逻辑应用的代码 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/

相关文章:

node.js - azure webapp Node 默认启动脚本

azure - 能否将列设置为 Azure 逻辑应用中 SQL 插入行的可选列?

Azure 逻辑应用程序 - 检查多个条件

.net - Azure 服务总线主题分区

java - 如何使用 JAVA 以编程方式为事件中心创建消费者组?

azure - cosmosdb 模拟器没有给出任何结果

azure - 尝试从逻辑应用调用 Azure 函数时出现 "Unauthorized"错误

c# - Azure 服务总线订阅指标

C# - Azure 服务总线 - 在给定时间后取消消息处理

azure - 使用 Terraform 配置 Azure AD Databricks SCIM 应用程序