public ActionResult CreateMessage(QueueMessageModel message) { if (ModelState.IsValid) { // Retrieve storage account from connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the queue client. CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); // Retrieve a reference to a queue. CloudQueue queue = queueClient.GetQueueReference("my-gab-queue"); // Create the queue if it doesn't already exist queue.CreateIfNotExists(); // Convert the message to a CloudQueueMessage object var messageAsJson = JsonConvert.SerializeObject(message); var cloudQueueMessage = new CloudQueueMessage(messageAsJson); // Create a message and add it to the queue. queue.AddMessage(cloudQueueMessage); return(RedirectToAction("Index", "Home")); } return(View(message)); }
public static QueueMessage ToDomain(this QueueMessageModel model) { return(new QueueMessage { Id = model.Id, QueueName = model.QueueName, SerializedContent = model.SerializedContent, CreationDateTime = model.CreateDateTime }); }
private string GetQueueMessage() { QueueMessageModel model = new QueueMessageModel() { TransactionId = Guid.NewGuid().ToString(), SenderType = SenderType.Admin }; return(JsonConvert.SerializeObject(model)); }
private async Task ProcessQueueMessageAsync(ProcessMessageEventArgs arg) { string body = arg.Message.Body.ToString(); QueueMessageModel queueMessageModel = JsonConvert.DeserializeObject <QueueMessageModel>(body); System.Console.WriteLine($"The queue message body is {queueMessageModel.TransactionId}"); await arg.CompleteMessageAsync(arg.Message); }
static void UpdateDatabase(QueueMessageModel model) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "UPDATE Parcari SET STARE_PARCARE = '" + model.SituatieParcari + "' WHERE ID_PARCARE = " + model.ParcareId; cmd.Connection = _conn; _conn.Open(); cmd.ExecuteNonQuery(); _conn.Close(); }
public ActionResult CreateMessage(QueueMessageModel message) { if (ModelState.IsValid) { // TODO: Insert add message to queue logic here return(RedirectToAction("Index", "Home")); } return(View(message)); }
public async Task <Guid> SaveAsync(string queueName, QueueMessageModel queueMessage, CancellationToken cancellationToken = default) { var message = new Message.DataAccess.Models.Message(queueName, queueMessage); await this.messages.Messages.AddAsync(message); await this.messages.SaveChangesAsync(cancellationToken); await this.games.SaveChangesAsync(cancellationToken); return(message.Id); }
public ActionResult CreateMessage(QueueMessageModel message) { if (ModelState.IsValid) { // Retrieve connection string. var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString"); var queue = CreateQueue(connectionString); // Convert the message to a CloudQueueMessage object var messageAsJson = JsonConvert.SerializeObject(message); var cloudQueueMessage = new CloudQueueMessage(messageAsJson); // Create a message and add it to the queue. queue.AddMessage(cloudQueueMessage); return(RedirectToAction("Index", "Home")); } return(View(message)); }
public IActionResult GetDataFromQueue(QueueMessageModel queueMessage) { _mediator.Send(new SaveQueueMessageCommand(queueMessage.Id, queueMessage.Title, queueMessage.Completed)); return(Ok()); }
public void Consume(QueueMessageModel model) { var job = model.Data as Job; if (job == null) { return; } var key = string.Format(CACHED_JOB_KEY, job.Id); var status = _cacheManager.Get <ProcessCache <JobStatus> >(key); if (status != null) { //Injection time is early than Last completed time //Injection time is set in JobInjector if (job.CheckPointTime < status.CompletedTimeUtc) { return; } if (status.Value == JobStatus.Running) { //Check the service is still running by heartbeat, otherwise maybe crashed var heatBeat = _cacheManager.Get <CacheEntity <int> >(status.MachineKey); if (heatBeat != null) { return; } } } //Set Cache to stop other thread, Default to cache for 1 day var cacheEntity = new ProcessCache <JobStatus>() { IpAddress = HostInfo.IpAddress, MacAddress = HostInfo.MacAddress, MachineKey = HostInfo.MachineKey, ProcessId = Process.GetCurrentProcess().Id, ThreadId = Thread.CurrentThread.ManagedThreadId, CreateTimeUtc = DateTime.UtcNow, Value = JobStatus.Running }; _cacheManager.Set(key, cacheEntity, 60 * 24); try { var type = _jobHooks.FirstOrDefault(m => m.FullName == job.FullName); if (type != null) { var hook = _lifetimeScope.Resolve(type) as IJobHook; Execute(hook, job.Id); } cacheEntity.Value = JobStatus.Completed; } catch (Exception ex) { _log.Error(ex.Message, ex); cacheEntity.Value = JobStatus.Stopped; } finally { cacheEntity.CompletedTimeUtc = DateTime.UtcNow; _cacheManager.Set(key, cacheEntity, 60 * 24); //Update } }