private static void PublishRetry() { var messages = MessageSvc.LoadPublishFailedMessage(AppConfiguration.AppSettings.PublishReloadTimeSpan ?? 2); foreach (var message in messages) { try { var msg = new MessageTransit.TextMessage() { MessageText = message.MessageText }; msg.putHeaders(BuiltinKeys.Exchange, message.Exchange); msg.putHeaders(BuiltinKeys.Topic, message.Topic); msg.putHeaders(BuiltinKeys.TraceId, message.MessageId.ToString()); msg.putHeaders(BuiltinKeys.SearchKey, message.HashFingerprint); MessageSvc.UpdateMessageStatusToPrepared(message.MessageId.Value); if (!MessageCenter.Startup.ProducerContainer.Send(msg)) { MessageSvc.UpdateMessageStatusToPublishFailed(message.MessageId.Value); } } catch (Exception ex) { Logger.WriteLog(ex.ToString(), "PublishRetry_Exception"); } } }
public IActionResult ManaualProcess(Guid messageId, string topic) { var message = MessageSvc.LoadMessage(messageId, topic); var msg = new TextMessage() { MessageText = message.MessageText }; msg.putHeaders(BuiltinKeys.TraceId, messageId.ToString()); msg.putHeaders(BuiltinKeys.Topic, topic); Stopwatch stopwatch = new Stopwatch(); IMonitor monitor = new SqlMonitor(); try { var processor = new RestApiProcessor(); stopwatch.Restart(); var result = (processor.Process(msg)).Result; stopwatch.Stop(); MessageSuccessEventArgs args = new MessageSuccessEventArgs(msg, stopwatch.ElapsedMilliseconds); monitor.onEvent(args); return(Json(new { Success = true, Message = "处理成功!" })); } catch (Exception ex) { stopwatch.Stop(); MessageExceptionEventArgs args = new MessageExceptionEventArgs(msg, ex, stopwatch.ElapsedMilliseconds); monitor.onEvent(args); } return(Json(new { Success = true, Message = "处理失败!" })); }
public IActionResult LoadMessages(MessageQueryFilter filter, DataTableQueryRequest request) { filter.BuildQueryFilter(request); IEnumerable <SubscribeMessage> messages; int totalCount = 0; if (filter.OnlyFailedMessage.HasValue && filter.OnlyFailedMessage.Value) { messages = MessageSvc.LoadFailedMessages(filter, out totalCount); } else { messages = MessageSvc.LoadMessages(filter, out totalCount); } var data = new { Success = true, sEcho = 0, iTotalRecords = totalCount, iTotalDisplayRecords = totalCount, aaData = messages }; return(Json(data)); }
public static int DeleteMessageTo(int id) { Message message = MessageSvc.RetrieveById(id)[0]; message.IsDelTo = true; MessageSvc.Update(message); return(0); }
public IActionResult Publish([FromBody] TextMessageModel message) { if (string.IsNullOrWhiteSpace(message.Topic)) { return(Json(new { Code = 1, Desc = "Topic不能为空" })); } var topic = TopicSvc.LoadTopicByTopicName(message.Topic); if (topic == null || topic.Status == -1) { return(Json(new { Code = 1, Desc = "无效的topic" })); } if (string.IsNullOrWhiteSpace(message.MessageText)) { return(Json(new { Code = 1, Desc = "MessageText不能为空" })); } //应是每天相同的消息不能超过多少条 //if(MessageSvc.ExistsMessage(message.MessageText)) //{ // return Json(new { Code = 1, Desc = "重复的MessageText" }); //} try { Guid messageid = Guid.NewGuid(); var msg = new TextMessage() { MessageText = message.MessageText }; msg.putHeaders(BuiltinKeys.Exchange, topic.ExchangeName); msg.putHeaders(BuiltinKeys.Topic, message.Topic); msg.putHeaders(BuiltinKeys.TraceId, messageid.ToString()); msg.putHeaders(BuiltinKeys.SearchKey, message.ReferenceIndentifier); MessageSvc.CreateMessage(new Message() { MessageId = messageid, Exchange = topic.ExchangeName, Topic = message.Topic, MessageText = message.MessageText, ReferenceIdentifier = message.ReferenceIndentifier }); if (!MessageCenter.Startup.ProducerContainer.Send(msg)) { MessageSvc.UpdateMessageStatusToPublishFailed(messageid); return(Json(new { Code = -1, Desc = "发送失败" })); } return(Json(new { Code = 0, Desc = "发送成功" })); } catch (Exception ex) { Logger.WriteLog(ex.ToString(), "MessagePublish_Exception"); } return(Json(new { Code = -1, Desc = "发送失败" })); }
public static int GetMessageTo(int id, ref List <Message> messages) { messages = MessageSvc.RetrieveByTo(id); foreach (Message message in messages) { if (message.IsDelTo == true) { messages.Remove(message); } } return(0); }
public IActionResult LoadMessage(Guid messageId, string topic) { var message = MessageSvc.LoadMessage(messageId, topic); var data = new { Success = true, Data = message }; return(Json(data)); }
public void onEvent(MessageEventArgs e) { if (e is MessageSuccessEventArgs) { MessageSuccessEventArgs args = e as MessageSuccessEventArgs; MessageSvc.UpdateMessageStatusToSuccess(Guid.Parse(args.message.Headers[BuiltinKeys.TraceId]), args.message.Headers[BuiltinKeys.Topic], args.milliseconds); } else if (e is MessageExceptionEventArgs) { MessageExceptionEventArgs args = e as MessageExceptionEventArgs; MessageSvc.UpdateMessageStatusToFail(new ProcessFailRecord() { MessageId = Guid.Parse(args.message.Headers[BuiltinKeys.TraceId]), Topic = args.message.Headers[BuiltinKeys.Topic], FailRecord = args.ex.Message, TimePeriod = args.milliseconds }); #region 邮件通知 #endregion } }
public static int DelMessage(int id) { MessageSvc.Delete(id); return(0); }
public static int MessageAll() { MessageSvc.RetrieveAll(); return(0); }
public static int Send(Message message) { MessageSvc.Create(message); return(0); }