0

CloudQueueMessage(byte[])コンストラクタを使用してメッセージを投稿するストレージキューがあります。私は、次のシグネチャでwebjob機能でメッセージを処理しようとした:Azure WebJobs QueueTriggerは、メッセージのbyte []本文を文字列に変換しようとします。

public static void ConsolidateDomainAuditItem([QueueTrigger("foo")] CloudQueueMessage msg) 

私は例外

UserTypeArgumentBindingProvider.BindAsyncのコードを見てみると
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() 

と一致失敗を取得し、それが明確に渡されることを期待し本文がJSONオブジェクトのメッセージです。また、名前のUserType...は、POCOをバインドすることを想定しています。

しかし、MSDNの記事How to use Azure queue storage with the WebJobs SDKは明らかにあなたは、次のタイプでQueueTriggerを使用することができます

と述べている:

  • string
  • JSON
  • byte[]
  • としてシリアライズA POCOタイプCloudQueueMessage

なぜ私のメッセージにバインドされていませんか?

答えて

0

WebJobs SDKのパラメータバインディングは、魔法のパラメータ名に大きく依存します。 [QueueTrigger(...)] stringは任意のパラメータ名を許可しているようですが(MSDN記事には例としてlogMessage,inputText,queueMessage,blobNameなどが含まれています)、[QueueTrigger(...)] CloudQueueMessageにはパラメータ名をmessageとする必要があります。パラメータの名前をmsgからmessageに変更すると、バインディングが修正されます。

残念ながら、私はこれを明示的に述べている文書は認識していません。

+1

パラメータの名前はバインディングロジックをまったく考慮しません。必要な名前を付けることができます。おそらく、あなたの機能を働かせるために何か他の変化が起こったでしょうか?それはパラメータ名にすることはできません:) – mathewc

0

代わりにこれを試してみてください:

公共の静的な無効ConsolidateDomainAuditItem([QueueTrigger( "foo" という)] []メッセージをバイト)の

CloudQueueMessageは通常、バインディングがラッパーを取り除くと、あなたを許可取得、ラッパーです代わりにコンテンツを扱う

関連する問題