我有一個天青函數,它接受從IoTHub並把它的消息上用於處理一個給定的隊列存儲帳戶的名稱。隊列在由傳入消息數據運行時動態地確定並放置在隊列具有短ExpirationTime如我只想消息持續幾秒鐘:指定從天青功能使用鍵入CloudQueue
#r "Microsoft.WindowsAzure.Storage"
#r "Newtonsoft.Json"
using System;
using Microsoft.WindowsAzure.Storage.Queue;
using Newtonsoft.Json;
public static void Run(MyType myEventHubMessage, IBinder binder, TraceWriter log)
{
int TTL = 3;
var data = JsonConvert.SerializeObject(myEventHubMessage);
var msg = new CloudQueueMessage(data);
string outputQueueName = myEventHubMessage.DeviceId;
QueueAttribute queueAttribute = new QueueAttribute(outputQueueName);
CloudQueue outputQueue = binder.Bind<CloudQueue>(queueAttribute);
outputQueue.AddMessage(msg, TimeSpan.FromSeconds(TTL), null, null, null);
}
public class MyType
{
public string DeviceId { get; set; }
public double Field1 { get; set; }
public double Field2 { get; set; }
public double Field3 { get; set; }
}
此,運作良好,郵件是寫入我的隊列。但是,它正在寫入的隊列不是我想要使用的存儲帳戶!它似乎從其他地方獲取存儲帳戶?!?
我在function.json
連接屬性:
{
"bindings": [
{
"type": "eventHubTrigger",
"name": "myEventHubMessage",
"direction": "in",
"path": "someiothub",
"connection": "IoTHubConnectionString"
},
{
"type": "CloudQueue",
"name": "$return",
"queueName": "{DeviceId}",
"connection": "NAME_OF_CON_STRING_I_WANT_TO_USE",
"direction": "out"
}
],
"disabled": false
}
但它被完全忽略。面對面,我可以從JSON中完全刪除值或鍵/值對,該功能仍在運行,並寫入似乎是某個默認存儲帳戶的地方。
我試着加入[StorageAccount("NAME_OF_CON_STR_I_WANT_TO_USE")]
屬性我運行的功能,但也似乎被忽略,我也嘗試創建一個屬性陣列和傳球都QueueAttribute和StorageAccountAttribute
到binder.Bind<T>(attributeArray)
但抱怨說,它不能接受的數組。
有誰知道首先從哪裏獲得存儲帳戶,它正在使用,更重要的是我可以如何設置存儲帳戶名稱?
感謝
感謝您的答覆。這是記錄在任何地方?我在數組中傳遞相同的錯誤:2017-06-13T09:43:56.381(20,65):error CS1503:Argument 1:無法從'System.Attribute []'轉換爲'System.Attribute' – LDJ
我找不到文檔...你確定使用'Binder'(而不是'IBinder')和'BindAsync'(而不是'Bind')嗎?適用於我。 – Mikhail
對不起,你是對的。忘了將IBinder更改爲Binder。現在就像魅力一樣。再次感謝您的幫助 :) – LDJ