我的实体类
public class VerifyVariableEntity : TableEntity
{
public VerifyVariableEntity()
{
}
public VerifyVariableEntity(string consumerId, string score)
{
PartitionKey = consumerId;
RowKey = score;
}
public string ConsumerId { get; set; }
public string Score { get; set; }
}
我正在从 Azure 服务总线队列中获取数据,然后对其进行反序列化,最后尝试将其存储到 Azure 表存储中。下面是我从服务总线队列中获取数据并将其存储到 Azure 表存储中的实现。
class Program
{
static void Main(string[] args)
{
var connectionString = "myconnectionString";
var queueName = "myqueueName";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("test");
table.CreateIfNotExists();
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
client.OnMessage(message =>
{
var bodyJson = new StreamReader(message.GetBody<Stream>(), Encoding.UTF8).ReadToEnd();
var myMessage = JsonConvert.DeserializeObject<VerifyVariable>(bodyJson);
Console.WriteLine(bodyJson);
Console.WriteLine(myMessage.ConsumerId);
Console.WriteLine(myMessage.Score);
var VerifyVariableEntityObject = new VerifyVariableEntity()
{
ConsumerId = myMessage.ConsumerId,
Score = myMessage.Score
};
TableOperation insertOperation = TableOperation.Insert(VerifyVariableEntityObject);
// Execute the insert operation.
table.Execute(insertOperation);
});
Console.ReadLine();
}
}