服务总线连接器和 "raw" 文本 (Content-Type)
Service Bus Connector and "raw" Text (Content-Type)
好的。
我正在编写 POC(概念验证)逻辑应用程序。
逻辑应用有一个连接到队列的服务总线连接器。
我正在使用 peek/complete/abandon。
我编写了一个将消息写入队列的客户端应用程序(dotnet c# 控制台应用程序)(与逻辑应用程序部分无关)。
我正在将内容类型设置为 "text/plain"。
string payLoad = @"{ ""myid"": ""1000"", ""mymessage"": ""1000 is great"" , ""myboolean"" : ""true"" }";
QueueClient queueClient = /* not seen here */;
brokeredMsg = new BrokeredMessage(payLoad) { ContentType = System.Net.Mime.MediaTypeNames.Text.Plain };
queueClient.Send(brokeredMsg);
现在我使用 Service Bus Explorer (4.0.104),我在队列中看到消息
问题是当我的逻辑应用程序运行时,它没有看到 plain-text/json。
你可以看到它拾取了 content-type。
但是内容本身乱七八糟。
有没有办法用这个触发器获得 raw-text?
注意,文档说:
let's look at the two Content-Types that don't require conversion or
casting that you can use in a logic app: application/json and
text/plain.
来自 :
https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-content-type
https://docs.microsoft.com/en-us/azure/connectors/connectors-create-api-servicebus
我的 C# 控制台应用程序 packages.config(与逻辑应用程序无关,但包括完整性)
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" />
<package id="WindowsAzure.ServiceBus" version="2.1.4.0" targetFramework="net45" />
</packages>
追加:
我需要做两件事才能让它工作
一个:
我不得不稍微更改 "sender" 代码。
QueueClient queueClient = /* not seen here */;
string ct = System.Net.Mime.MediaTypeNames.Text.Plain;
/* see https://social.msdn.microsoft.com/Forums/en-US/8fbf2391-8440-46db-bb47-648daccf46fd/servicebus-output-json-is-being-wrapped-in-a-xml-header-in-logic-app?forum=azurelogicapps and https://abhishekrlal.com/2012/03/30/formatting-the-content-for-service-bus-messages/ */
string payLoad = @"{ ""myid"": ""1000"", ""mymessage"": ""1000 is great"" , ""myboolean"" : ""true"" }";
brokeredMsg = new BrokeredMessage(new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(Convert.ToString(payLoad))), true) { ContentType = ct };
queueClient.Send(brokeredMsg);
我使用了 Derek Li 给我的提示。
我接受了他的回答 the-answer,但请注意,我必须做的比他建议的要多一些。由于我更改了发件人代码,上面的代码具有网址。
简而言之,我使用的 BrokeredMessage 的构造函数为我选择了一个特定的序列化程序。
代理消息(对象)
通过以下方式从给定对象初始化 BrokeredMessage class 的新实例
将 DataContractSerializer 与二进制 XmlDictionaryWriter 结合使用。
在我找出答案后,我找到了这个 SOF 答案:
Azure Service Bus Serialization Type
您可以使用表达式 @base64ToString(triggerBody()?['ContentData'])"
将其转换为字符串。
好的。
我正在编写 POC(概念验证)逻辑应用程序。
逻辑应用有一个连接到队列的服务总线连接器。
我正在使用 peek/complete/abandon。
我编写了一个将消息写入队列的客户端应用程序(dotnet c# 控制台应用程序)(与逻辑应用程序部分无关)。
我正在将内容类型设置为 "text/plain"。
string payLoad = @"{ ""myid"": ""1000"", ""mymessage"": ""1000 is great"" , ""myboolean"" : ""true"" }";
QueueClient queueClient = /* not seen here */;
brokeredMsg = new BrokeredMessage(payLoad) { ContentType = System.Net.Mime.MediaTypeNames.Text.Plain };
queueClient.Send(brokeredMsg);
现在我使用 Service Bus Explorer (4.0.104),我在队列中看到消息
问题是当我的逻辑应用程序运行时,它没有看到 plain-text/json。
你可以看到它拾取了 content-type。
但是内容本身乱七八糟。
有没有办法用这个触发器获得 raw-text?
注意,文档说:
let's look at the two Content-Types that don't require conversion or casting that you can use in a logic app: application/json and text/plain.
来自 : https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-content-type
https://docs.microsoft.com/en-us/azure/connectors/connectors-create-api-servicebus
我的 C# 控制台应用程序 packages.config(与逻辑应用程序无关,但包括完整性)
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" />
<package id="WindowsAzure.ServiceBus" version="2.1.4.0" targetFramework="net45" />
</packages>
追加:
我需要做两件事才能让它工作
一个:
我不得不稍微更改 "sender" 代码。
QueueClient queueClient = /* not seen here */;
string ct = System.Net.Mime.MediaTypeNames.Text.Plain;
/* see https://social.msdn.microsoft.com/Forums/en-US/8fbf2391-8440-46db-bb47-648daccf46fd/servicebus-output-json-is-being-wrapped-in-a-xml-header-in-logic-app?forum=azurelogicapps and https://abhishekrlal.com/2012/03/30/formatting-the-content-for-service-bus-messages/ */
string payLoad = @"{ ""myid"": ""1000"", ""mymessage"": ""1000 is great"" , ""myboolean"" : ""true"" }";
brokeredMsg = new BrokeredMessage(new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(Convert.ToString(payLoad))), true) { ContentType = ct };
queueClient.Send(brokeredMsg);
我使用了 Derek Li 给我的提示。
我接受了他的回答 the-answer,但请注意,我必须做的比他建议的要多一些。由于我更改了发件人代码,上面的代码具有网址。
简而言之,我使用的 BrokeredMessage 的构造函数为我选择了一个特定的序列化程序。
代理消息(对象) 通过以下方式从给定对象初始化 BrokeredMessage class 的新实例 将 DataContractSerializer 与二进制 XmlDictionaryWriter 结合使用。
在我找出答案后,我找到了这个 SOF 答案:
Azure Service Bus Serialization Type
您可以使用表达式 @base64ToString(triggerBody()?['ContentData'])"
将其转换为字符串。