public async Task DeleteStorageQueue(string queueName) { CloudQueue table = GetStorageQueue(queueName); await table.DeleteIfExistsAsync(); }
/// <summary> /// Create, list and delete queues /// </summary> /// <param name="cloudQueueClient"></param> /// <returns></returns> private static async Task ListQueuesSample(CloudQueueClient cloudQueueClient) { // Create 3 queues. // Create the queue name -- use a guid in the name so it's unique. string baseQueueName = "demotest-" + System.Guid.NewGuid().ToString(); // Keep a list of the queues so you can compare this list // against the list of queues that we retrieve. List <string> queueNames = new List <string>(); for (int i = 0; i < 3; i++) { // Set the name of the queue, then add it to the generic list. string queueName = baseQueueName + "-0" + i; queueNames.Add(queueName); // Create the queue with this name. Console.WriteLine("Creating queue with name {0}", queueName); CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(queueName); try { await cloudQueue.CreateIfNotExistsAsync(); Console.WriteLine(" Queue created successfully."); } catch (StorageException exStorage) { Common.WriteException(exStorage); Console.WriteLine( "Please make sure your storage account is specified correctly in the app.config - then restart the sample."); Console.WriteLine("Press any key to exit"); Console.ReadLine(); throw; } catch (Exception ex) { Console.WriteLine(" Exception thrown creating queue."); Common.WriteException(ex); throw; } } Console.WriteLine(string.Empty); Console.WriteLine("List of queues in the storage account:"); // List the queues for this storage account QueueContinuationToken token = null; List <CloudQueue> cloudQueueList = new List <CloudQueue>(); do { QueueResultSegment segment = await cloudQueueClient.ListQueuesSegmentedAsync(baseQueueName, token); token = segment.ContinuationToken; cloudQueueList.AddRange(segment.Results); }while (token != null); try { foreach (CloudQueue cloudQ in cloudQueueList) { Console.WriteLine("Cloud Queue name = {0}", cloudQ.Name); } } catch (Exception ex) { Console.WriteLine(" Exception thrown listing queues."); Common.WriteException(ex); throw; } // Now clean up after yourself, using the list of queues that you created in case there were other queues in the account. foreach (string oneQueueName in queueNames) { CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(oneQueueName); cloudQueue.DeleteIfExists(); } }
public static string GetQueuesStatus(QueueType type, SourceType source) { CloudQueue queue = GetCloudQueue(type, source); return(string.Format("{0} queue of {1} source has #{2} messages.", queue.Name, source, queue.RetrieveApproximateMessageCount())); }
public static void DeleteQueueMessage(QueueType type, SourceType source, CloudQueueMessage message) { CloudQueue queue = GetCloudQueue(type, source); queue.DeleteMessage(message); }
static async Task <int> Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.local.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); storageConnectionString = configuration["storageConnectionString"]; trainingQueueName = configuration["TrainingQueueName"]; var shortStorageConnectionString = storageConnectionString.Substring(0, 50); Console.WriteLine($"Storage connection string = {shortStorageConnectionString}"); Console.WriteLine($"Training Queue Name = {trainingQueueName}"); var rootCommand = new RootCommand { new Option <string>( "--documentFormat", description: "The document format for which the training assets should be uploaded"), new Option <string>( "--labellingContainerSasUrl", description: "SAS Token for container that holds the folder with the labelling and training assets"), new Option <string>( "--blobContainerFolder", getDefaultValue: () => null, description: "The name of a folder within the blob container where the assets from the labelling tool aare stored"), }; rootCommand.Description = "This command triggers training of a forms recognizer model, based on assets produced by the labelling tool and stored in a folder in blob storage."; try { rootCommand.Handler = CommandHandler.Create <string, string, string>(async(documentFormat, labellingContainerSasUrl, blobContainerFolder) => { try { Console.WriteLine($"The value for --documentFormat is: {documentFormat}"); if (string.IsNullOrEmpty(documentFormat)) { throw new Exception($"--documentFormat {documentFormat} must be provided"); } Console.WriteLine($"The value for --labellingContainerSasUrl is: {labellingContainerSasUrl}"); if (string.IsNullOrEmpty(labellingContainerSasUrl)) { throw new Exception($"--blobContainer {labellingContainerSasUrl} must be provided"); } Console.WriteLine($"The value for --blobContainerFolder is: {blobContainerFolder}"); if (string.IsNullOrEmpty(blobContainerFolder)) { throw new Exception($"--blobContainerFolder {blobContainerFolder} must be provided"); } // Get hold of the storage account CloudStorageAccount storageAccount = null; try { storageAccount = CloudStorageAccount.Parse(storageConnectionString); TrainingRequestMessage trainingRequestMessage = new TrainingRequestMessage { BlobFolderName = blobContainerFolder, BlobSasUrl = labellingContainerSasUrl, DocumentFormat = documentFormat, IncludeSubFolders = "false", UseLabelFile = "true" }; CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); // Retrieve a reference to a container. CloudQueue queue = queueClient.GetQueueReference(trainingQueueName); // Create the queue if it doesn't already exist await queue.CreateIfNotExistsAsync(); CloudQueueMessage message = new CloudQueueMessage(JsonConvert.SerializeObject(trainingRequestMessage)); await queue.AddMessageAsync(message); } catch (Exception e) { throw; } Console.WriteLine("done."); } catch (Exception e) { Console.WriteLine(e.Message); } } ); } catch (Exception e) { Console.WriteLine(e.Message); return(-1); } return(rootCommand.InvokeAsync(args).Result); }
/// <summary> /// Delete the queue that was created for this sample /// </summary> /// <param name="queue">The sample queue to delete</param> public async Task DeleteQueueAsync(CloudQueue queue) { Console.WriteLine("10. Delete the queue"); await queue.DeleteAsync(); }
/// <summary> /// Checks existence of the queue. /// </summary> /// <param name="queue">Cloud queue object</param> /// <param name="requestOptions">Queue request options</param> /// <param name="operationContext">Operation context</param> /// <returns>True if the queue exists, otherwise false</returns> public bool DoesQueueExist(CloudQueue queue, QueueRequestOptions requestOptions, OperationContext operationContext) { return(queue.Exists(requestOptions, operationContext)); }
public override bool OnStart() { // Set the maximum number of concurrent connections. ServicePointManager.DefaultConnectionLimit = 12; // Obtain connection to this application's storage account // using credentials set in role properties and embedded in .cscfg file. // It will be used to access both blobs and queues. CloudStorageAccount storageAccount = CloudStorageAccount.Parse (RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString")); // Set up blob container, creating if necessary // Instantiate the logical client object used for // communicating with a blob container. Trace.TraceInformation("Creating videos blob container"); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Associate that logical client object with a physical // blob container. If we knew that the blob container // already existed, this would be all that we needed. videoBlobContainer = blobClient.GetContainerReference("videos"); // Create the physical blob container underlying the logical // CloudBlobContainer object, if it doesn't already exist. A // production app will frequently not do this, instead // requiring the initial administrative provisioning // process to set up blob containers and other storage structures. if (videoBlobContainer.CreateIfNotExists()) { // Enable public access on the newly created "photogallery" container. // i.e. set the permission on the blob container to allow anonymous access. videoBlobContainer.SetPermissions( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); } // Set up queue, creating if necessary // Instantiate a client object for communicating // with a message queue Trace.TraceInformation("Creating thumbnails queue"); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); // Connect the client object to a specific CloudQueue // logical object in the storage service. If we were // sure that physical queue underlying this logical // object already existed, this would be all we needed. videosQueue = queueClient.GetQueueReference("videoqueue"); // Create the physical queue underlying the logical // CloudQueue object, if it doesn't already exist. A // production app will frequently not do this, instead // requiring the initial administrative provisioning // process to set up queues and other storage structures. videosQueue.CreateIfNotExists(); Trace.TraceInformation("Storage initialized"); Trace.TraceInformation("Thumbnails_WebRole is running"); return(base.OnStart()); }
/// <summary> /// Create an cloud queue on azure if not exists. /// </summary> /// <param name="queue">Cloud queue object.</param> /// <param name="options">Queue request options</param> /// <param name="operationContext">Operation context</param> /// <returns>True if the queue did not already exist and was created; otherwise false.</returns> public bool CreateQueueIfNotExists(CloudQueue queue, QueueRequestOptions options, OperationContext operationContext) { return(queue.CreateIfNotExists(options, operationContext)); }
/// <summary> /// Delete the specified storage queue. /// </summary> /// <param name="queue">Cloud queue object</param> /// <param name="options">Queue request options</param> /// <param name="operationContext">Operation context</param> public void DeleteQueue(CloudQueue queue, QueueRequestOptions options, OperationContext operationContext) { queue.Delete(options, operationContext); }
/// <summary> /// Fetch queue attributes /// </summary> /// <param name="queue">Cloud queue object</param> /// <param name="options">Queue request options</param> /// <param name="operationContext">Operation context</param> public void FetchAttributes(CloudQueue queue, QueueRequestOptions options, OperationContext operationContext) { queue.FetchAttributes(options, operationContext); }
public static bool Exists(this CloudQueue queue) { return(queue.ExistsAsync().GetAwaiter().GetResult()); }
public static void DeleteMessage(this CloudQueue queue, CloudQueueMessage message) { queue.DeleteMessageAsync(message).GetAwaiter().GetResult(); }
public static void Clear(this CloudQueue queue) { queue.ClearAsync().GetAwaiter().GetResult(); }
/// <summary> /// Get queue permission /// </summary> /// <param name="options">Queue request options </param> /// <param name="operationContext">Operation context</param> /// <returns>QueuePermissions object</returns> public QueuePermissions GetPermissions(CloudQueue queue, QueueRequestOptions options, OperationContext operationContext) { return(queue.GetPermissions(options, operationContext)); }
private static async Task ProcessAsync(string sourcePath, string storageConnectionString, string queueName) { CloudStorageAccount storageAccount = null; CloudQueue queue = null; // Check whether the connection string can be parsed. if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount)) { try { // Create the CloudQueueClient that represents the queue endpoint for the storage account. CloudQueueClient cloudQueueClient = storageAccount.CreateCloudQueueClient(); // Create a queue called 'quickstartqueues' and append a GUID value so that the queue name // is unique in your storage account. queue = cloudQueueClient.GetQueueReference(queueName); await queue.CreateIfNotExistsAsync(); Console.WriteLine("Connected to queue '{0}'", queue.Name); Console.WriteLine(); // Recursively publish file names of an adls directory await PublishFolder(sourcePath, queue); //// Get list of files //// Check ADLS directory access rights //bool adlsAccess = client.CheckAccess(sourcePath, "r-x"); //// Console.WriteLine(adlsAccess.ToString()); //if(adlsAccess) //{ // // Reset queue // if (_flag_WriteMode == "reset"){await queue.ClearAsync();} // var stream = client.EnumerateDirectory(sourcePath); // string currentFullFileName = string.Empty; // int _BUFFER_LIMIT = 1000; // int msgCnt = 0; // int buffCnt = 0; // Console.WriteLine("Starting queue insert {0} UTC +0:00", DateTime.UtcNow); // foreach (var item in stream) // { // if (item.Type == DirectoryEntryType.FILE && !item.FullName.ToLower().Contains(".txt")) // { // currentFullFileName = item.FullName; // // Broadcast each path as a message // // Create a message and add it to the queue. Set expiration time to 7 days. // CloudQueueMessage message = new CloudQueueMessage(currentFullFileName); // await queue.AddMessageAsync(message, new TimeSpan(7,0,0,0), null, null, null); // //Console.WriteLine("Added message '{0}' to queue '{1}'", message.Id, queue.Name); // //Console.WriteLine("Message insertion time: {0}", message.InsertionTime.ToString()); // //Console.WriteLine("Message expiration time: {0}", message.ExpirationTime.ToString()); // //Console.WriteLine(); // msgCnt++; // buffCnt++; // if (buffCnt%_BUFFER_LIMIT == 0) // { // buffCnt = 0; // Console.WriteLine("Added {0} messages to queue '{1}' @ {2}", msgCnt, queue.Name, DateTime.UtcNow); // } // } else if (item.Type == DirectoryEntryType.DIRECTORY) // { // } // } // Console.WriteLine("Queue filled at {0} UTC +0:00", DateTime.UtcNow); // Console.WriteLine("{0} messages inserted", msgCnt); //} } catch (StorageException ex) { Console.WriteLine("Error returned from Azure Storage: {0}", ex.Message); } finally { } } else { Console.WriteLine( "A connection string has not been defined in the system environment variables. " + "Add a environment variable named 'storageconnectionstring' with your storage " + "connection string as a value."); } }
/// <summary> /// Get queue permission async /// </summary> /// <param name="queue"></param> /// <param name="requestOptions"></param> /// <param name="operationContext"></param> /// <returns></returns> public Task <QueuePermissions> GetPermissionsAsync(CloudQueue queue, QueueRequestOptions requestOptions, OperationContext operationContext) { return(queue.GetPermissionsAsync(requestOptions, operationContext)); }
private static async Task ProcessStep( QueueMessage queueMessage, CloudBlobContainer blobContainer, CloudQueue consumptionQueue, CloudQueue dedicatedQueue, CloudTable resultMessageTable, TraceWriter traceWriter) { var blobId = queueMessage.ContentId; var pipelineMessage = await GetPipelineMessageFromBlobAsync(blobContainer, blobId); if (pipelineMessage.Steps.Count == 0) { pipelineMessage.Steps = GetStepsForProcess(queueMessage.From).ToList(); } var step = SelectStep(pipelineMessage); if (step != null) { var nextPipelineMessage = await step.ProcessAsync(pipelineMessage, traceWriter); nextPipelineMessage.Id = Guid.NewGuid(); nextPipelineMessage.NextStep++; var newBlobId = nextPipelineMessage.Id; await SaveNewPipelineMessageToBlobAsync(blobContainer, newBlobId, nextPipelineMessage); queueMessage.ContentId = newBlobId; await PushMessageToCorrectQueueAsync(queueMessage, consumptionQueue, dedicatedQueue); } else { await resultMessageTable.CreateIfNotExistsAsync(); var resultMessage = new ResultMessage { RowKey = Guid.NewGuid().ToString(), PartitionKey = string.Empty, ContentId = queueMessage.ContentId.ToString(), From = queueMessage.From, Created = queueMessage.Created, Completed = DateTimeOffset.Now, }; await resultMessageTable.ExecuteAsync(TableOperation.Insert(resultMessage)); } async Task <PipelineMessage> GetPipelineMessageFromBlobAsync(CloudBlobContainer container, Guid id) { var blob = container.GetBlockBlobReference(id.ToString()); var blobString = await blob.DownloadTextAsync(); return(JsonConvert.DeserializeObject <PipelineMessage>(blobString)); } async Task SaveNewPipelineMessageToBlobAsync(CloudBlobContainer container, Guid id, PipelineMessage message) { var blob = container.GetBlockBlobReference(id.ToString()); await blob.UploadTextAsync(JsonConvert.SerializeObject(message)); } ConcurrentQueue <Type> GetStepsForProcess(string processName) { var stepMaps = new ConcurrentDictionary <string, ConcurrentQueue <Type> > { [_freshFruitsSource] = new ConcurrentQueue <Type>(new Type[] { typeof(FreshFruitPrintInfo), typeof(FreshFruitGetWithMaxCrates), typeof(FreshFruitPrintInfo) }), [_freshFruitsSource] = new ConcurrentQueue <Type>(new Type[] { typeof(DnDCharactersConvertToJson), typeof(DnDCharactersStatsByClass) }), [_helloWorldSource] = new ConcurrentQueue <Type>(new Type[] { typeof(HelloWorldDuplicate), typeof(HelloWorldDuplicate), typeof(HelloWorldDuplicate), typeof(HelloWorldDuplicate) }) }; if (stepMaps.TryGetValue(processName, out var stepMap)) { return(stepMap); } else { throw new Exception($"Steps for process '{processName}' are not configured."); } } IStep SelectStep(PipelineMessage message) { IStep nextStep = null; if (message.NextStep >= message.Steps.Count) { traceWriter.Warning($"Reached max number of configured steps: {message.NextStep}"); } else { var nextStepType = message.Steps[message.NextStep]; nextStep = (IStep)Activator.CreateInstance(nextStepType); } return(nextStep); } }
/// <summary> /// set queue permission /// </summary> /// <param name="queue"></param> /// <param name="queuePermissions"></param> /// <param name="requestOptions"></param> /// <param name="operationContext"></param> public void SetPermissions(CloudQueue queue, QueuePermissions queuePermissions, QueueRequestOptions requestOptions, OperationContext operationContext) { queue.SetPermissions(queuePermissions, requestOptions, operationContext); }
public void ProcessQueue(CloudBlockBlob blob, CloudQueueMessage receivedMessage, CloudQueue urbanWaterQueue) { }
public static async Task AddMessageToQueueAsync(CloudQueue cloudQueue, JObject messageJson) { CloudQueueMessage queueMessage = await CreateQueueMessageAsync(cloudQueue, messageJson); var result = cloudQueue.UpdateMessageAsync(queueMessage, new TimeSpan(0, 0, 0), MessageUpdateFields.Content | MessageUpdateFields.Visibility); }
public Guid EnqueueProvisioningJob(ProvisioningJob job) { // Prepare the Job ID Guid jobId = Guid.NewGuid(); // Connect to the Infrastructural Site Collection using (var context = PnPPartnerPackContextProvider.GetAppOnlyClientContext(PnPPartnerPackSettings.InfrastructureSiteUrl)) { // Set the initial status of the Job job.JobId = jobId; job.Status = ProvisioningJobStatus.Pending; // Convert the current Provisioning Job into a Stream Stream stream = job.ToJsonStream(); // Get a reference to the target library Web web = context.Web; List list = web.Lists.GetByTitle(PnPPartnerPackConstants.PnPProvisioningJobs); Microsoft.SharePoint.Client.File file = list.RootFolder.UploadFile(String.Format("{0}.job", jobId), stream, false); Microsoft.SharePoint.Client.User ownerUser = web.EnsureUser(job.Owner); context.Load(ownerUser); context.ExecuteQueryRetry(); ListItem item = file.ListItemAllFields; item[PnPPartnerPackConstants.ContentTypeIdField] = PnPPartnerPackConstants.PnPProvisioningJobContentTypeId; item[PnPPartnerPackConstants.TitleField] = job.Title; item[PnPPartnerPackConstants.PnPProvisioningJobStatus] = ProvisioningJobStatus.Pending.ToString(); item[PnPPartnerPackConstants.PnPProvisioningJobError] = String.Empty; item[PnPPartnerPackConstants.PnPProvisioningJobType] = job.GetType().FullName; FieldUserValue ownerUserValue = new FieldUserValue(); ownerUserValue.LookupId = ownerUser.Id; item[PnPPartnerPackConstants.PnPProvisioningJobOwner] = ownerUserValue; item.Update(); context.ExecuteQueryRetry(); // Check if we need to enqueue a message in the Azure Storage Queue, as well // This happens when the Provisioning Job has to be executed in Continous mode if (PnPPartnerPackSettings.ContinousJobHandlers.ContainsKey(job.GetType())) { // Get the storage account for Azure Storage Queue CloudStorageAccount storageAccount = CloudStorageAccount.Parse(PnPPartnerPackSettings.StorageQueueConnectionString); // Get queue ... and create if it does not exist CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); CloudQueue queue = queueClient.GetQueueReference(PnPPartnerPackSettings.StorageQueueName); queue.CreateIfNotExists(); // Add entry to queue ContinousJobItem content = new ContinousJobItem { JobId = job.JobId }; queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(content))); } } return(jobId); }
/// <summary> /// Initializes a new instance of the ReliableQueueClient class. /// </summary> /// <param name="queue">cloud queue</param> public ReliableQueueClient(CloudQueue queue) { this.cloudQueue = queue; this.timer = new Timer(this.TimerCallback, null, TimerPeriod, TimerPeriod); }
public static void AddQueueMessage(QueueType type, SourceType source, string message) { CloudQueue queue = GetCloudQueue(type, source); queue.AddMessage(new CloudQueueMessage(message)); }
public static async void Run(TimerInfo rewardsRequestTrxTimer, ICollector <string> errormessage, TraceWriter log) { log.Verbose($"C# timer function processed a request.", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); try { // Retrieve storage account from connection string CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["jermsstorage_STORAGE"].ToString()); // Create the queue client CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); // Retrieve a reference to a queue CloudQueue queue = queueClient.GetQueueReference("submitrewardsrequestqueue"); // Get the next message IEnumerable <CloudQueueMessage> retrievedMessage = queue.GetMessages(Convert.ToInt32(ConfigurationManager.AppSettings["ReadRewardsRequestReceivedFromQueueBatchSize"])); log.Verbose($"After the reading of queue message = {retrievedMessage.Count()}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); foreach (var item in retrievedMessage) { string inputmessage = item.AsString; //Process the message in less than 30 seconds, and then delete the message queue.DeleteMessage(item.Id, item.PopReceipt); JObject inputJSON = JObject.Parse(inputmessage); JSchema objectschema = new JSchema(); objectschema = JSchema.Parse(Common.Constants.RewardRequestSchema.RequestSchema); if (inputJSON["TransactionType"] != null) { if (inputJSON["TransactionType"].ToString() == TransactionTypeEnum.Qualify.GetDescription() || inputJSON["TransactionType"].ToString() == TransactionTypeEnum.Terminate.GetDescription() || inputJSON["TransactionType"].ToString() == TransactionTypeEnum.Reactivate.GetDescription()) { objectschema = JSchema.Parse(Common.Constants.RewardRequestSchema.Terminate_Reactivate_Qualify_Schema); } if (inputJSON["TransactionType"].ToString() == TransactionTypeEnum.Reward.GetDescription()) { string product = inputJSON.SelectToken("Reward.ProductCode").ToString().Replace("{", "").Replace("}", ""); string program = inputJSON.SelectToken("Reward.ProgramName").ToString().Replace("{", "").Replace("}", ""); if (product != null && program != null) { List <SqlParameter> GetFulfillmentRuleParams = new List <SqlParameter>(); GetFulfillmentRuleParams.Add(new SqlParameter("@Product", product.ToString())); GetFulfillmentRuleParams.Add(new SqlParameter("@Program", program.ToString())); var ApiName = MSSQLConnection.ExecuteStoredProcedure <string>(USPContstants.GetFulfillmentRule, GetFulfillmentRuleParams).FirstOrDefault(); log.Verbose($"APIName ={ApiName}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); log.Verbose($"Program ={program}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); log.Verbose($"Product ={product}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); if (ApiName == "Order") { objectschema = JSchema.Parse(Common.Constants.RewardRequestSchema.OrderRewardSchema); inputJSON.Add("IsOrder", true); } else { objectschema = JSchema.Parse(Common.Constants.RewardRequestSchema.RewardSchema); } } } if (inputJSON["TransactionType"].ToString() == TransactionTypeEnum.ProgramUpdateSourceSystem.GetDescription()) { objectschema = JSchema.Parse(Common.Constants.RewardRequestSchema.ProgramUpdateSchema); } } //Message schema validation valid = inputJSON.IsValid(objectschema, out messages); log.Verbose($"Valid ={valid}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); inputJSON.Add("IsValid", valid); var messageJSON = ""; if (messages.Count > 0) { messageJSON = JsonConvert.SerializeObject(messages); } inputJSON.Add("ValidationMessage", messageJSON); log.Verbose($"Validation message = {messageJSON}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); saverewardsobj = inputJSON.ToString(); log.Verbose($"Published message ={saverewardsobj}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); // Call SaveRewardsTrx to save rewards transaction. using (HttpClient client = new HttpClient()) { var SaveRewardsTrxEndpoint = ConfigurationManager.AppSettings["SaveRewardsTrxEndpoint"].ToString(); var accept = "application/json"; client.DefaultRequestHeaders.Add("Accept", accept); using (var response = await client.PostAsync(SaveRewardsTrxEndpoint, new StringContent(saverewardsobj, Encoding.UTF8, "application/x-www-form-urlencoded"))) { if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; log.Verbose($"Response ={result}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); } else { var result = response.Content.ReadAsStringAsync().Result; log.Verbose($"StatusCode ={response.StatusCode} ReasonPhrase ={response.ReasonPhrase}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); log.Verbose($"Response ={result}", "JE.RMS.Services.ScheduledReadRewardsRequestRecieved"); } } } } } catch (Exception ex) { log.Error($"Exception ={ex}", ex, "JE.RMS.Services.OnRewardsRequestRecieved"); errormessage.Add(JsonConvert.SerializeObject(ex).ToString()); } }
/// <summary> /// Represents the base object type for a queue entity in the queue service. /// </summary> /// <param name="cloudQueue">Represents a Windows Azure queue.</param> public EntityContext(CloudQueue cloudQueue) { _cloudQueue = cloudQueue; }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; DiagnosticMonitor.Start("DiagnosticsConnectionString"); // For information on handling configuration changes // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. RoleEnvironment.Changing += RoleEnvironmentChanging; // read storage account configuration settings CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) => configSetter(RoleEnvironment.GetConfigurationSettingValue(configName))); var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"); // initialize blob storage CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient(); container = blobStorage.GetContainerReference("converteddata"); // initialize queue storage CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient(); queue = queueStorage.GetQueueReference("workercommands"); Trace.TraceInformation("Creating container and queue..."); bool storageInitialized = false; while (!storageInitialized) { try { // create the blob container and allow public access container.CreateIfNotExist(); var permissions = container.GetPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Container; container.SetPermissions(permissions); // create the message queue queue.CreateIfNotExist(); storageInitialized = true; } catch (StorageClientException e) { if (e.ErrorCode == StorageErrorCode.TransportError) { Trace.TraceError("Storage services initialization failure. " + "Check your storage account configuration settings. If running locally, " + "ensure that the Development Storage service is running. Message: '{0}'", e.Message); Thread.Sleep(5000); } else { throw; } } } return(base.OnStart()); }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="message">The poison message</param> /// <param name="poisonQueue">The poison queue</param> public PoisonMessageEventArgs(CloudQueueMessage message, CloudQueue poisonQueue) { Message = message; PoisonQueue = poisonQueue; }
public MessageQueue(CloudQueue queue) { this.queue = queue; }
public CloudQueueWrapper(CloudQueue cloudQueue) { _cloudQueue = cloudQueue ?? throw new ArgumentNullException(nameof(cloudQueue)); }
// A production app would also include an OnStop override to provide for // graceful shut-downs of worker-role VMs. See // http://azure.microsoft.com/en-us/documentation/articles/cloud-services-dotnet-multi-tier-app-storage-3-web-role/#restarts public override bool OnStart() { // Set the maximum number of concurrent connections. ServicePointManager.DefaultConnectionLimit = 12; // Read database connection string and open database. var dbConnString = CloudConfigurationManager.GetSetting("ContosoAdsDbConnectionString"); db = new ContosoAdsContext(dbConnString); // Open storage account using credentials from .cscfg file. var storageAccount = CloudStorageAccount.Parse (RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString")); Trace.TraceInformation("Creating images blob container"); var blobClient = storageAccount.CreateCloudBlobClient(); imagesBlobContainer = blobClient.GetContainerReference("images"); if (imagesBlobContainer.CreateIfNotExists()) { // Enable public access on the newly created "images" container. imagesBlobContainer.SetPermissions( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); } Trace.TraceInformation("Creating images queue"); CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); imagesQueue = queueClient.GetQueueReference("images"); imagesQueue.CreateIfNotExists(); Trace.TraceInformation("Storage initialized"); return base.OnStart(); }