繁体   English   中英

在消息服务总线中发送 XML 并在逻辑应用程序中解析

[英]Send XML in message service bus and parse it in logic app

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

在这种情况下,我使用了 2 个逻辑应用程序,其中 1 个通过服务总线发送 XML 消息,另一个接收它。

Logic App - 1 的流程(向服务总线发送 XML 消息)

在此处输入图像描述

Logic App - 2 的流程(从服务总线接收 XML 消息并解析它)

您可以将 XML 转换为 JSON 然后使用 Parse_JSON 解析它。

在此处输入图像描述

结果:

在此处输入图像描述

逻辑应用程序的代码视图 - 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"
                }
            }
        }
    }
}

逻辑应用程序的代码视图 - 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"
                }
            }
        }
    }
}

暂无
暂无

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

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