【发布时间】:2016-05-06 11:16:29
【问题描述】:
我有一个存储队列,我将使用CloudQueueMessage(byte[]) 构造函数构造的消息发布到该队列。然后,我尝试使用以下签名处理 webjob 函数中的消息:
public static void ConsolidateDomainAuditItem([QueueTrigger("foo")] CloudQueueMessage msg)
我得到一个持续失败的异常
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Program.ConsolidateDomainAuditItem ---> System.InvalidOperationException: Exception binding parameter 'msg' ---> System.Text.DecoderFallbackException: Unable to translate bytes [FF] at index -1 from specified code page to Unicode.
at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)
at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes)
at System.Text.UTF8Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDecoder)
at System.String.CreateStringFromEncoding(Byte* bytes, Int32 byteLength, Encoding encoding)
at System.Text.UTF8Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
at Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage.get_AsString()
at Microsoft.Azure.WebJobs.Host.Storage.Queue.StorageQueueMessage.get_AsString()
at Microsoft.Azure.WebJobs.Host.Queues.Triggers.UserTypeArgumentBindingProvider.UserTypeArgumentBinding.BindAsync(IStorageQueueMessage value, ValueBindingContext context)
at Microsoft.Azure.WebJobs.Host.Queues.Triggers.QueueTriggerBinding.<BindAsync>d__0.MoveNext()
看UserTypeArgumentBindingProvider.BindAsync的代码,很明显是期望传入一个消息体为JSON对象的消息。并且名称的UserType... 也暗示它期望绑定一个POCO。
然而 MSDN 文章 How to use Azure queue storage with the WebJobs SDK 明确指出
您可以将 QueueTrigger 与以下类型一起使用:
string- 序列化为 JSON 的 POCO 类型
byte[]CloudQueueMessage
那么为什么它没有绑定到我的消息?
【问题讨论】:
标签: binding parameter-passing azure-webjobs azure-webjobssdk