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,例如 string、byte[] 和自定义类型,也会发生此错误。
问题似乎是 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/