Azure Functions v2 BrokeredMessage 作为来自 ServiceBus 的输入
Azure Functions v2 BrokeredMessage as input from ServiceBus
我正在关注一个针对 v1 函数的示例,以及我想要从中得到的我无法在 v2 中复制的示例。
我想要 Azure 函数签名中的 BrokeredMessage。
public static async Task WhatIsTheTime(
[ServiceBusTrigger(queueName: QueueName, Connection = ConnectionStringKey)]
BrokeredMessage message,
ILogger log)
{
var myObj = message.GetBody<MyType>();
// whatever
}
主要是因为它包含很多方便的元数据,而且每次我决定想要不同的东西时,我都会更改签名。也因为如上例所示,获取主体非常容易。
然而,无论我拥有何种开箱即用的设置,似乎都对这个想法感到愤怒。它要我做的是:
public static async Task WhatIsTheTime(
[ServiceBusTrigger(queueName: QueueName, Connection = ConnectionStringKey)]
MyType myObj,
ILogger log)
{
// whatever
}
并为我完成第一步。
如果我这样做,一切都会很开心,我们都可以回家了。但是我不想要这个,我宁愿完整的 BrokeredMessage。
无论我如何尝试打包 body 的内容,它在我的代码执行之前都惨遭失败,给我带来了许多不同的错误(取决于我如何打包它),但很明显;这个:
Exception while executing function: Exception binding parameter Expecting element 'BrokeredMessage'
它试图将 BrokeredMessage 的 BODY 反序列化为 BrokeredMessage!
是什么赋予了?我读过一些文章,指出将 BrokeredMessage 放在签名中可以使这件事变得简单。我是不是缺少配置选项或 smth?
Azure Functions v2 不再使用 BrokeredMessage,而是使用 Microsoft.Azure.ServiceBus.Message。
这与损坏的wire compatibility issue有关。
如果您的原始代码使用采用对象而非流的构造函数构造 BrokeredMessage
,这将导致新的 .NET Standard 客户端失败。除非使用扩展方法来检索正文,我认为 Azure Functions 不会这样做。
如果您可以选择更新和重新部署 senders/publishers,您 可以 通过发送 MemoryStream
函数能够处理它的字节数。
Here 是来自 Azure Functions Service Bus Trigger 文档的信息,说 Azure Functions V2 中的服务总线消息支持 Meessage
而不是 BrokeredMessage
.
我正在关注一个针对 v1 函数的示例,以及我想要从中得到的我无法在 v2 中复制的示例。
我想要 Azure 函数签名中的 BrokeredMessage。
public static async Task WhatIsTheTime(
[ServiceBusTrigger(queueName: QueueName, Connection = ConnectionStringKey)]
BrokeredMessage message,
ILogger log)
{
var myObj = message.GetBody<MyType>();
// whatever
}
主要是因为它包含很多方便的元数据,而且每次我决定想要不同的东西时,我都会更改签名。也因为如上例所示,获取主体非常容易。
然而,无论我拥有何种开箱即用的设置,似乎都对这个想法感到愤怒。它要我做的是:
public static async Task WhatIsTheTime(
[ServiceBusTrigger(queueName: QueueName, Connection = ConnectionStringKey)]
MyType myObj,
ILogger log)
{
// whatever
}
并为我完成第一步。
如果我这样做,一切都会很开心,我们都可以回家了。但是我不想要这个,我宁愿完整的 BrokeredMessage。
无论我如何尝试打包 body 的内容,它在我的代码执行之前都惨遭失败,给我带来了许多不同的错误(取决于我如何打包它),但很明显;这个:
Exception while executing function: Exception binding parameter Expecting element 'BrokeredMessage'
它试图将 BrokeredMessage 的 BODY 反序列化为 BrokeredMessage!
是什么赋予了?我读过一些文章,指出将 BrokeredMessage 放在签名中可以使这件事变得简单。我是不是缺少配置选项或 smth?
Azure Functions v2 不再使用 BrokeredMessage,而是使用 Microsoft.Azure.ServiceBus.Message。
这与损坏的wire compatibility issue有关。
如果您的原始代码使用采用对象而非流的构造函数构造 BrokeredMessage
,这将导致新的 .NET Standard 客户端失败。除非使用扩展方法来检索正文,我认为 Azure Functions 不会这样做。
如果您可以选择更新和重新部署 senders/publishers,您 可以 通过发送 MemoryStream
函数能够处理它的字节数。
Here 是来自 Azure Functions Service Bus Trigger 文档的信息,说 Azure Functions V2 中的服务总线消息支持 Meessage
而不是 BrokeredMessage
.