c# - 由于内容类型,ServiceBusTrigger 消息无法读取 BrokeredMessages

标签 c# azure-functions servicebus azure-servicebus-topics

C# .NET Core Azure Functions v2; Microsoft.Azure.ServiceBus 3.2.0、Microsoft.Azure.WebJobs 3.0.2、Microsoft.Azure.WebJobs.Extensions.ServiceBus 3.0.1

我们收到使用旧的 ServiceBus 包(WindowsAzure.ServiceBus、Microsoft.ServiceBus)发布的 BrokeredMessages,Content-Type:text/plain

我们在azure函数中使用ServiceBusTrigger来消费:

[ServiceBusTrigger("topic", "subscription", Connection = "appsetting")]Message message,

尝试使用新包从主题消费时

(microsoft.azure.servicebus) 我们遇到以下错误:

System.Private.CoreLib: Exception while executing function: Function1. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'message'. System.Private.CoreLib: Unable to translate bytes [99] at index 60 from specified code page to Unicode.

即使我们尝试使用其他类型而不是 Message,例如 stringbyte[] 和自定义类型,也会发生此错误。

问题似乎是 Content-Type:

Content-Type: text/plain

其他 BrokeredMessage 组合似乎可以正常工作(其中没有一个是空的 Content-Type); stream+none, stream+text/plain, string+none 和 string+text/plain;charset=unicode.

我们可以在我们的 webjobs 中绕过这个(未经测试),因为我们可以在运行时访问 MessageReceiver 或其他 ServiceBus 配置来处理这个问题,但到目前为止我们还没有找到任何解决方案或方法来处理这个 Azure在我们进入函数内部之前,作为框架的函数会抛出错误。

有没有其他人遇到过这个错误?我目前的做法是错误的吗?

我们无法控制消息的生成,因此无法轻易更改它。

其他人有类似配置的不同问题:BrokeredMessage send and Message consumer in Azure Function v2

最佳答案

您是否尝试过指定编码和内容类型?像:Content-Type: text/plain;charset=unicode

关于c# - 由于内容类型,ServiceBusTrigger 消息无法读取 BrokeredMessages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53524051/

相关文章:

C# iTextSharp 单个单元格中的多种字体

c# - 你如何检查一个窗口是否在 Gtk 中最大化?

c# - 数据库 "openpg"不存在严重性 : FATAL Code: 3D000

c# - 部署的 Azure Function (v2) 未运行

json - 如何使用 Node.js 从 Azure 函数返回 JSON 对象

c# - .NET Core - 能够连接到 Azure 应用程序配置但无法返回任何配置值?

c# - Microsoft ServiceBus - 参数实体名称为 null 或为空

c# - 格式化类似于 ToString ("G29") 的十进制数字加上千位分隔符

deployment - Windows Server 的服务总线 - 在客户端上自动部署证书

java - 将消息从死信移回主题