使用 PowerApps AzureServiceBus 连接器 SendMessage ContentData

问题描述

我尝试使用的 PowerApps - Azure 服务总线连接器功能定义为:

ServiceBus.SendMessage(EntityName:Text,{systemProperties :Text,ContentData:Blob,ContentType:Text,Properties:Table,MessageId:Text,To:Text,ReplyTo:Text,ReplyToSesionId:Text,Label:Text,ScheduledEnquequeTimeUtc:DateTime,SessionId:Text,CorrelationId:Text,SequenceNumber:Number,LockToken:Text,TimetoLive:Text})

如您所见,ContentData 是 Blob 类型,而 PowerApps 似乎无法将文本字符串转换为 Blob。因此,尽管下面将发送消息,但在服务总线资源管理器或接收应用程序中检查时内容为空。请注意,在收到的消息中可以看到 Properties 表数据和 Label 值。

ServiceBus.SendMessage("TestTopic",{ContentData:"HelloWorld",Label:"MyLabel",Properties:Table({key:"MyUserDefinedKey",value:"MyUserDefinedkeyvalue"})})

是否有直接用文本填充 ContentData 的方法?我希望使用 PowerApp 文本输入。

我尝试将 ContentType 和 ContentData 更改为各种选项,但没有成功。

解决方法

据我所知 in the docsContentData 的数据类型是 bytes,我认为 PowerApps 不支持(查找支持的数据类型 here)。

可以尝试的一件事是ContentData: JSON("Hello World",JSONFormat.IncludeBinaryData)

这是我所知道的在 PowerApps 中处理二进制数据的唯一方法,但我不确定它是否会编码文本。

,

您可以使用 Properties 参数在 Power Apps 服务总线连接器 SendMessage 调用中发送自定义属性。 Properties 参数采用包含特定行的键值对的表。

我没有找到详细记录的 ContentData 参数。在我的测试中,它采用强制 base64 编码的数据 URI 字符串值。不幸的是,在 canvas Power App 中没有内置的 base64 编码方式。如果参数值的格式不正确,则生成的 Servivce Bus 队列消息将具有空的 ContentData 值。下面是一个将新消息发送到队列的示例,设置代理属性:标签和三个自定义属性,以及文本“Hello world!”在 ContentData 参数中。

示例:

ServiceBus.SendMessage("p1imagecaptureevents",{ContentType:"text/plain",Properties:Table (
    {key: "Label",value: "labelvalue2"},{key: "myFirstFieldName",value: "'My first field's value8'"},{key: "mySecondFieldName",value: "My second field's value5"},{key: "myOtherFieldName",value: "More values5"}),ContentData:"data:text/plain;base64,SGVsbG8gd29ybGQh"  // "Hello world!" base64 encoded text
})