public SbqOppResult Opp(QueueMethod method, byte[] item) { // SbqOppResult ru = new SbqOppResult(); if (QueueMethod.Add == method) { _byteList.Enqueue(item); ru.oppSucess = true; } else if (QueueMethod.Shift == method && _byteList.Count > 0) { ru.oppSucess = true; ru.item = _byteList.Dequeue(); } else if (QueueMethod.Peek == method && _byteList.Count > 0) { ru.oppSucess = true; ru.item = _byteList.Peek(); } else if (QueueMethod.Count == method) { ru.oppSucess = true; ru.count = _byteList.Count; } return ru; }
public SbqOppResult Opp(QueueMethod method, byte[] item) { // SbqOppResult ru = new SbqOppResult(); if (QueueMethod.Add == method) { _byteList.Enqueue(item); ru.oppSucess = true; } else if (QueueMethod.Shift == method && _byteList.Count > 0) { ru.oppSucess = true; ru.item = _byteList.Dequeue(); } else if (QueueMethod.Peek == method && _byteList.Count > 0) { ru.oppSucess = true; ru.item = _byteList.Peek(); } else if (QueueMethod.Count == method) { ru.oppSucess = true; ru.count = _byteList.Count; } return(ru); }
public async Task Send(object entity, QueueMethod method) { try { var connect = GetChannel(); var envelop = new Message(); envelop.Entity = entity.GetType().Name; envelop.Envelop = JsonConvert.SerializeObject(entity); envelop.Method = (int)method; var jsonSerializedMessage = JsonConvert.SerializeObject(envelop); var serializedMessage = Encoding.UTF8.GetBytes(jsonSerializedMessage); connect.BasicPublish(exchange: "", routingKey: RabbitConfig.QueueName, basicProperties: null, body: serializedMessage); } catch (Exception ex) { logger.LogError($"{nameof(QueueSender)}: An error has ocurred sending data to QueryDataBase.{Environment.NewLine}Ex: {ex.AllMessages()}{Environment.NewLine}{ex.StackTrace}"); //Send to errors queue } }
public SmqOppResult Opp(QueueMethod method, SessionMessage item) { // SmqOppResult ru = new SmqOppResult(); if (QueueMethod.Add == method) { _smsgList.Enqueue(item); ru.oppSucess = true; } else if (QueueMethod.Shift == method && _smsgList.Count > 0) { ru.oppSucess = true; ru.item = _smsgList.Dequeue(); } else if (QueueMethod.Peek == method && _smsgList.Count > 0) { ru.oppSucess = true; ru.item = _smsgList.Peek(); } else if (QueueMethod.Count == method) { ru.oppSucess = true; ru.count = _smsgList.Count; } return(ru); }
public async Task UpdateLike(Message message) { QueueMethod method = (QueueMethod)message.Method; Like like = JsonConvert.DeserializeObject <Like>(message.Envelop); User user = _userRepository.FindOne(like.UserId.ToLong()).Result; Article article = _articleRepository.FindOne(like.ArticleId.ToLong()).Result; using (TransactionScope scope = new TransactionScope()) { switch (method) { case QueueMethod.Insert: InsertLike(user.Id, article.Id, like.WritableRelation); UpdateArticleTotalCount(article); break; case QueueMethod.Update: throw new NotSupportedException($"Like feature does not support update."); case QueueMethod.Delete: DeleteLike(user.Id, article.Id); UpdateArticleTotalCount(article, false); break; default: throw new NotImplementedException($"Method {method.ToString()} doesn't have an implementation."); } scope.Complete(); } }
public SmqOppResult Opp(QueueMethod method, SessionMessage item) { // SmqOppResult ru = new SmqOppResult(); if (QueueMethod.Add == method) { _smsgList.Enqueue(item); ru.oppSucess = true; } else if (QueueMethod.Shift == method && _smsgList.Count > 0) { ru.oppSucess = true; ru.item = _smsgList.Dequeue(); } else if (QueueMethod.Peek == method && _smsgList.Count > 0) { ru.oppSucess = true; ru.item = _smsgList.Peek(); } else if (QueueMethod.Count == method) { ru.oppSucess = true; ru.count = _smsgList.Count; } return ru; }
public virtual async Task UpdateDB(Message message) { var entity = DeserializeEntity(message.Envelop); entity.WritableRelation = entity.Id.ToLong(); entity.Id = string.Empty; QueueMethod method = (QueueMethod)message.Method; switch (method) { case QueueMethod.Insert: Normalize(entity); await _repository.Insert(entity); break; case QueueMethod.Update: Normalize(entity); await _repository.Update(entity); break; case QueueMethod.Delete: await _repository.Delete(entity); break; default: throw new NotImplementedException($"Method '{method.ToString()}' not immplemented."); } }