我想将通过主题接收的数据存储到Azure表。 我为此使用Azure函数。
public static class Function1
{
[FunctionName("Function1")]
public static async Task Run([ServiceBusTrigger("simple_test_topic", "stt_subscription", AccessRights.Manage, Connection = "ServiceBusConnectionString")]string mySbMsg,
[Table("RoomBasicInformation")] CloudTable outputTable, TraceWriter log)
{
log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
RoomEntry re = new RoomEntry(){ PartKey = "hpk", RoomId = "13", Temperature = "10"};
var operation = TableOperation.Insert(re);
await outputTable.ExecuteAsync(operation);
}
}
public class RoomEntry : TableEntity
{
public string PartKey { get; set; }
public string RoomId { get; set; }
public string Temperature { get; set; }
}
但是在Visual Studio中执行它后,我得到了
mscorlib:执行函数Function1时发生异常。 Microsoft.WindowsAzure.Storage:远程服务器返回错误: (400)错误的请求。
答案 0 :(得分:0)
您应该初始化PartitionKey
的{{1}}和RowKey
。
修改TableEntity
以初始化这些值:
RoomEntity
您不需要public class RoomEntry : TableEntity
{
public RoomEntry()
{
}
public RoomEntry(string partitionKey, string roomId)
{
this.PartitionKey = partitionKey;
this.RowKey = roomId;
}
public string RoomId => this.RowKey;
public string Temperature { get; set; }
}
属性PartKey
已有该属性。
还可以将Azure函数中的TableEntity
初始化修改为:
RommEntity