public Processor(CloudStorageAccount account, string requestsQueueName, string responsesQueueName, string filesContainerName) { this.account = account; QueueUtilities qutil = new QueueUtilities(account); this.requests = qutil.CreateQueueIfNotExists(requestsQueueName); this.responses = qutil.CreateQueueIfNotExists(responsesQueueName); CloudBlobClient blobStorage = this.account.CreateCloudBlobClient(); this.files = blobStorage.GetContainerReference(filesContainerName); }
public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.WriteLine("NumberWorkerRole entry point called", "Information"); CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); QueueUtilities qutil = new QueueUtilities(account); CloudQueue queue = qutil.CreateQueueIfNotExists("numbers"); while (true) { CloudQueueMessage msg = queue.GetMessage(); if (msg != null) { int number = Convert.ToInt32(msg.AsString); Trace.WriteLine(string.Format("Processing number: {0}", number), "Information"); number--; if (number > 0) { CloudQueueMessage newmsg = new CloudQueueMessage(number.ToString()); queue.AddMessage(newmsg); } queue.DeleteMessage(msg); } else { Thread.Sleep(10000); Trace.WriteLine("Working", "Information"); } } }
public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.WriteLine("CollatzWorkerRole entry point called", "Information"); CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); QueueUtilities qutil = new QueueUtilities(account); CloudQueue queue = qutil.CreateQueueIfNotExists("numbers"); CloudQueueClient qclient = account.CreateCloudQueueClient(); for (int k = 0; k < 11; k++) { CloudQueue q = qclient.GetQueueReference("numbers"); MessageProcessor p = new MessageProcessor(q, this.ProcessMessage); p.Start(); } MessageProcessor processor = new MessageProcessor(queue, this.ProcessMessage); processor.Run(); }
public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.WriteLine("FractalWorkerRole entry point called", "Information"); CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); CloudBlobClient blobClient = account.CreateCloudBlobClient(); CloudBlobContainer blobContainer = blobClient.GetContainerReference("fractalsectors"); blobContainer.CreateIfNotExist(); QueueUtilities qutil = new QueueUtilities(account); CloudQueue queue = qutil.CreateQueueIfNotExists("fractaltoprocess"); CloudQueue outqueue = qutil.CreateQueueIfNotExists("fractalsectors"); Calculator calculator = new Calculator(); while (true) { CloudQueueMessage msg = queue.GetMessage(); if (msg != null) { Trace.WriteLine(string.Format("Processing {0}", msg.AsString)); SectorInfo info = SectorUtilities.FromMessageToSectorInfo(msg); if (info.Width > 100 || info.Height > 100) { Trace.WriteLine("Splitting message..."); for (int x = 0; x < info.Width; x += 100) { for (int y = 0; y < info.Height; y += 100) { SectorInfo newinfo = info.Clone(); newinfo.FromX = x + info.FromX; newinfo.FromY = y + info.FromY; newinfo.Width = Math.Min(100, info.Width - x); newinfo.Height = Math.Min(100, info.Height - y); CloudQueueMessage newmsg = SectorUtilities.FromSectorInfoToMessage(newinfo); queue.AddMessage(newmsg); } } } else { Trace.WriteLine("Processing message..."); Sector sector = calculator.CalculateSector(info); string blobname = string.Format("{0}.{1}.{2}.{3}.{4}", info.Id, sector.FromX, sector.FromY, sector.Width, sector.Height); CloudBlob blob = blobContainer.GetBlobReference(blobname); MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); foreach (int value in sector.Values) { writer.Write(value); } writer.Flush(); stream.Seek(0, SeekOrigin.Begin); blob.UploadFromStream(stream); stream.Close(); CloudQueueMessage outmsg = new CloudQueueMessage(blobname); outqueue.AddMessage(outmsg); } queue.DeleteMessage(msg); } else { Thread.Sleep(10000); Trace.WriteLine("Working", "Information"); } } }