Update:
You can pass message id and PopReceipt to your method:
static void Main(string[] args)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a container.
CloudQueue queue = queueClient.GetQueueReference("myqueue0905");
//Retrieve the cached approximate message count.
queue.FetchAttributes();
int? cachedMessageCount = queue.ApproximateMessageCount;
//get the message id and PopReceipt, or you can pass them from your api call.
string _id = "";
string _popreceipt = "";
if (cachedMessageCount != null)
{
foreach (CloudQueueMessage message in queue.GetMessages(cachedMessageCount.Value, TimeSpan.FromMinutes(3)))
{
_id = message.Id;
_popreceipt = message.PopReceipt;
Console.WriteLine("the id is:" + _id);
Console.WriteLine("the pop receipt is:" + _popreceipt);
}
}
//update queue message by using message id and PopReceipt
var msg = new CloudQueueMessage(_id, _popreceipt);
msg.SetMessageContent("a test messge 123456");
queue.UpdateMessage(msg, TimeSpan.FromSeconds(120.0),
MessageUpdateFields.Content | MessageUpdateFields.Visibility);
Console.WriteLine("complete update");
Console.ReadLine();
}
In your case, assume you already know the message id, then you can update your message via the id.
We need to iterate all the queue messages using the message id, to fetch the correct message you want to update.
Code like below:
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using System;
namespace ConsoleApp11
{
class Program
{
static void Main(string[] args)
{
//assume you know the message id
string message_id = "3798f6b6-1541-4421-b8de-79a8294edf49";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a container.
CloudQueue queue = queueClient.GetQueueReference("myqueue0905");
//Retrieve the cached approximate message count.
queue.FetchAttributes();
int? cachedMessageCount = queue.ApproximateMessageCount;
//if the queue is not null
if (cachedMessageCount != null)
{
foreach (CloudQueueMessage message in queue.GetMessages(cachedMessageCount.Value))
{
if (message.Id == message_id)
{
message.SetMessageContent("test updated content again");
queue.UpdateMessage(message, TimeSpan.FromSeconds(5.0),
MessageUpdateFields.Content | MessageUpdateFields.Visibility);
}
}
}
Console.ReadLine();
}
}
}