本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Queue.CloudQueue.GetMessage方法的典型用法代码示例。如果您正苦于以下问题:C# CloudQueue.GetMessage方法的具体用法?C# CloudQueue.GetMessage怎么用?C# CloudQueue.GetMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Queue.CloudQueue
的用法示例。
在下文中一共展示了CloudQueue.GetMessage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public override void Run()
{
storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
cmdQueue = storageAccount.CreateCloudQueueClient().GetQueueReference("krawlercmd");
urlQueue = storageAccount.CreateCloudQueueClient().GetQueueReference("krawlerurl");
errorQueue = storageAccount.CreateCloudQueueClient().GetQueueReference("krawlererror");
lastTenUrlQueue = storageAccount.CreateCloudQueueClient().GetQueueReference("lasttenurlcrawled");
index = storageAccount.CreateCloudTableClient().GetTableReference("krawlerindex");
visisted = new HashSet<string>();
cmdQueue.CreateIfNotExists();
urlQueue.CreateIfNotExists();
errorQueue.CreateIfNotExists();
lastTenUrlQueue.CreateIfNotExists();
// This is a sample worker implementation. Replace with your logic.
Trace.TraceInformation("WorkerRole entry point called", "Information");
Crawler crawler = new Crawler();
//cmdQueue.Clear();
//cmdQueue.AddMessage(new CloudQueueMessage("stop"));
while (true)
{
Thread.Sleep(500);
Trace.TraceInformation("Working", "Information");
CloudQueueMessage cmd = cmdQueue.PeekMessage();
if (cmd == null || cmd.AsString == "stop")
{
continue;
}
else if (cmd.AsString == "start")
{
CloudQueueMessage url = urlQueue.GetMessage();
if (!visisted.Contains(url.AsString))
{
crawler.Crawl(url.AsString);
visisted.Add(url.AsString);
}
urlQueue.DeleteMessage(url);
}
else if (cmd.AsString == "load" && urlQueue.PeekMessage() == null)
{
crawler.LoadQueue("http://www.cnn.com");
}
else
{
continue;
}
}
}
示例2: Run
public override void Run()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
datatable = tableClient.GetTableReference("datatable");
datatable.CreateIfNotExists();
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
urlQueue = queueClient.GetQueueReference("urlqueue");
urlQueue.CreateIfNotExists();
adminQueue = queueClient.GetQueueReference("adminqueue");
adminQueue.CreateIfNotExists();
ramCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");
cpuCounter = new System.Diagnostics.PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
crawler = new Crawler();
while (true)
{
Thread.Sleep(50);
//If there is something in the admin queue
if (adminQueue.PeekMessage() != null)
{
CloudQueueMessage message = adminQueue.GetMessage();
crawler.handleAdminMessage(message);
adminQueue.DeleteMessage(message);
}
if (urlQueue.PeekMessage() != null)
{
crawler.crawlingPhase(urlQueue.GetMessage());
}
}
}
示例3: QueueBase64EncodingTestDownloadMessageAndVerify
private static void QueueBase64EncodingTestDownloadMessageAndVerify(CloudQueue queue, CloudQueue queueRefWithoutBase64Encoding, byte[] originalData)
{
// Assumption: 2 of the same messages have been added
// If the message was uploaded with Base64Encoding, this function will also retrieve the message without Base64 encoding.
CloudQueueMessage readBack = queue.GetMessage();
if (!CompareByteArray(originalData, readBack.AsBytes))
{
string orignalData = PrintByteArray(originalData, "OriginalData");
string returnedData = PrintByteArray(readBack.AsBytes, "ReturnedData");
Assert.Fail("Data read back from server doesn't match the original data. \r\n{0}\r\n{1}", orignalData, returnedData);
}
queue.DeleteMessage(readBack);
if (queue.EncodeMessage)
{
CloudQueueMessage readBackWithoutBase64Encoding = queueRefWithoutBase64Encoding.GetMessage();
byte[] returnedDataWithoutBase64Encoding = Convert.FromBase64String(readBackWithoutBase64Encoding.AsString);
if (!CompareByteArray(originalData, returnedDataWithoutBase64Encoding))
{
string orignalData = PrintByteArray(originalData, "OriginalData");
string returnedData = PrintByteArray(returnedDataWithoutBase64Encoding, "ReturnedDataWithoutBase64Encoding");
Assert.Fail("Data read back from server doesn't match the original data. \r\n{0}\r\n{1}", orignalData, returnedData);
}
queueRefWithoutBase64Encoding.DeleteMessage(readBackWithoutBase64Encoding);
}
else
{
readBack = queue.GetMessage();
queue.DeleteMessage(readBack);
}
}
示例4: GetNewMessage
/// <summary>
/// Get the message from IN Queue
/// </summary>
/// <param name="myqueueClient">QueClient</param>
/// <returns>New Message, it can be null if it has not message</returns>
private CloudQueueMessage GetNewMessage(CloudQueueClient myqueueClient)
{
CloudQueueMessage currentMessage=null;
try
{
InWorkQueue = myqueueClient.GetQueueReference(myConfigData.inWorkQueueName);
currentMessage = InWorkQueue.GetMessage();
}
catch (Exception X)
{
string txt = string.Format("[{0}] at {1} has an error: {2}", this.GetType().FullName, "GetNewMessage", X.Message);
Trace.TraceError(txt);
}
return currentMessage;
}
示例5: TryGetMessage
public GetMessageResult TryGetMessage(CloudQueue queue, out MessageEnvelope envelope)
{
CloudQueueMessage message = null;
envelope = null;
try
{
message = queue.GetMessage(new TimeSpan(0, 2, 0)); // 2 min timeout
}
catch (Exception ex)
{
this.Observer.Notify(new FailedToReadMessage(ex, queue.Name));
return GetMessageResult.Exception;
}
if (message == null)
{
return GetMessageResult.Empty;
}
if (message.DequeueCount > RetryCount)
{
this.Observer.Notify(new RetrievedPoisonMessage(queue.Name, message.Id));
return GetMessageResult.Retry;
}
try
{
envelope = SerializationUtility.Deserialize<MessageEnvelope>(this.Serializer, message.AsBytes);
//try download from blob
if (!envelope.MessageReference.IsLoaded)
{
if (envelope.MessageReference.StorageContainer != this.CloudBlob.Uri.ToString())
{
throw new InvalidOperationException("Wrong container used!");
}
var blob = this.CloudBlob.GetBlobReferenceFromServer(envelope.MessageReference.StorageReference);
var messageType = Type.GetType(envelope.MessageReference.MessageTypeName);
var stream = new MemoryStream();
blob.DownloadToStream(stream);
envelope.MessageReference.Message = SerializationUtility.Deserialize(messageType, this.Serializer, stream.ToArray()) as IMessage;
}
envelope.TransportMessage = message;
}
catch (StorageException ex)
{
this.Observer.Notify(new FailedToAccessStorage(ex, queue.Name, message.Id));
return GetMessageResult.Retry;
}
catch (Exception ex)
{
this.Observer.Notify(new FailedToDeserializeMessage(ex, queue.Name, message.Id));
return GetMessageResult.Exception;
}
return GetMessageResult.Success;
}