Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 将表存储密钥作为消息放入Azure队列_.net_Azure_Azure Storage_Azure Table Storage_Azure Storage Queues - Fatal编程技术网

.net 将表存储密钥作为消息放入Azure队列

.net 将表存储密钥作为消息放入Azure队列,.net,azure,azure-storage,azure-table-storage,azure-storage-queues,.net,Azure,Azure Storage,Azure Table Storage,Azure Storage Queues,我能够将行键和分区键插入Azure表存储: TableOperation insertOperation=TableOperation.Insert(customer1); 表.Execute(插入操作); StoreKeyInQ(插入操作) “客户属性”如下所示: public class CustomerEntity : TableEntity { public CustomerEntity(string ID, string Name) {

我能够将行键和分区键插入Azure表存储:

TableOperation insertOperation=TableOperation.Insert(customer1); 表.Execute(插入操作); StoreKeyInQ(插入操作)

“客户属性”如下所示:

public class CustomerEntity : TableEntity
    {
        public CustomerEntity(string ID, string Name)
        {
            this.PartitionKey = ID;
            this.RowKey = Name;
        }

        public CustomerEntity() { }

        public string path { get; set; }


    }
 public void StoreKeyInQ(TableOperation insertOperation)
    {
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
        //craete a queue client
        CloudQueueClient cloudQueueClient = storageAccount.CreateCloudQueueClient();
        //retrive a reference to a container
        CloudQueue cloudQueue = cloudQueueClient.GetQueueReference("myqueue");
        //create the queue if does not exists
        cloudQueue.CreateIfNotExists();

       // Create a message and add it to the queue.
       CloudQueueMessage message = new CloudQueueMessage(insertOperation); //Here is the error as "CloudQueueMessage" can't take a argument type "TableOperation"
       queue.AddMessage(message);
    }
我已经编写了创建队列的代码,如下所示:

public class CustomerEntity : TableEntity
    {
        public CustomerEntity(string ID, string Name)
        {
            this.PartitionKey = ID;
            this.RowKey = Name;
        }

        public CustomerEntity() { }

        public string path { get; set; }


    }
 public void StoreKeyInQ(TableOperation insertOperation)
    {
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
        //craete a queue client
        CloudQueueClient cloudQueueClient = storageAccount.CreateCloudQueueClient();
        //retrive a reference to a container
        CloudQueue cloudQueue = cloudQueueClient.GetQueueReference("myqueue");
        //create the queue if does not exists
        cloudQueue.CreateIfNotExists();

       // Create a message and add it to the queue.
       CloudQueueMessage message = new CloudQueueMessage(insertOperation); //Here is the error as "CloudQueueMessage" can't take a argument type "TableOperation"
       queue.AddMessage(message);
    }
如何解决此错误?如何将表存储的“rowkey”和“partition”键都传递到队列中

  EDIT:
我已经为序列化添加了这两行,可以吗

 System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(customerEntity.GetType());
        CloudQueueMessage message = new CloudQueueMessage(x.ToString());
我的队伍是这样排的;但是,不确定这是否正确?请任何人澄清一下,这是正确的吗

如何解决此错误

如果要将消息插入队列中。我们可以得到操作队列

源代码演示

如何将表存储的“rowkey”和“partition”键都传递到队列中

  EDIT:
您可以将模型序列化为字符串,然后将其另存为消息,也可以使用自定义格式保存消息,例如消息格式:
RowKey,PartitionKey


其基本思想是将RowKey+PartitionKey都存储在队列中,并创建一个worker角色来从队列中检索密钥(RowKey+PartitionKey)

如果您只想检索队列消息,我们可以使用许多便宜的方法,例如或

更新:

请尝试使用以下代码

using Newtonsoft.Json;
CloudQueueMessage message = new CloudQueueMessage(JsonConvert.SerializeObject(customer1));
cloudQueue.AddMessage(message);


有关更多演示代码,请参阅或对象。

不确定您要执行的操作!您是想在队列中插入消息(为什么要创建整个表)还是想在表中插入实体(为什么要创建整个队列)?基本上,您的想法是在队列中存储RowKey+PartitionKey,并创建一个工作角色来检索键(RowKey+PartitionKey)从队列中。请编辑您的问题并包括您的
客户
型号的代码。基本上,您需要将模型序列化为字符串,然后将其保存为消息。在接收端,您将再次对其进行反序列化并获取对象,从那里您可以检索
PartitionKey
RowKey
值。您正在尝试将自定义对象插入队列,该队列只接受字节数组或字符串。您需要更改此设置(例如,发送JSON、csv、任何其他序列化为字符串或序列化为字节数组格式)。@GauravMantri我已按照您的指示编辑了此问题。希望我的编辑正确。OP已经有插入队列的信息。问题是他们试图插入一个自定义对象,其中队列只处理字节数组或字符串。另外,“如何处理队列消息”部分超出了这个问题的范围(好吧,它充其量是不明确的)。我已经用“CustomerEntity”更新了我的问题。你能对你的答案做更多的澄清吗?我已经用如何序列化或反序列化对象更新了答案。