//队列消息消费 public static void Recive <T>(ReceiveMessageDelegate <T> receiveMethod, MQType mqType) { if (!bSendMsgUseMQ) { return; } RabbitReceiveDic[mqType].Receive(receiveMethod); }
public static IDestination CreateDestination(this MQType type, string name) { switch (type) { case MQType.Queue: return(new ActiveMQQueue(name)); case MQType.Topic: return(new ActiveMQTopic(name)); default: throw new NotSupportedException($"{typeof(MQType).FullName}.{type.ToString()}"); } }
//将日志发送到队列中 protected override ExeResEdm SendLogToQueue(object model, MQType mqType) { if (mqType == MQType.TraceLog)//是操作轨迹类数据 { var item = model as Log_OperateTrace; ExeResEdm bOK = RabbitMQManager.Send(item, mqType); return(bOK); } else //是监控类数据 { var item = model as Log_SystemMonitorMQ; ExeResEdm bOK = RabbitMQManager.Send(item, mqType); return(bOK); } }
/// <summary> /// 创建消息生产者 /// </summary> /// <param name="brokerUri">消息队列地址</param> /// <param name="type">消息队列类型</param> /// <param name="name">消息队列名称</param> /// <param name="onException">异常处理</param> public SimpleProducer(string brokerUri, MQType type, string name, Action <Exception> onException = null) { if (string.IsNullOrWhiteSpace(brokerUri)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(brokerUri)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(name)); } _brokerUri = brokerUri; _name = name; _destination = type.CreateDestination(name); _onException = onException; }
/// <summary> /// 创建消费者 /// </summary> /// <param name="brokerUri">消息队列地址</param> /// <param name="type">消息队列类型</param> /// <param name="name">消息队列名称</param> /// <param name="messageReceived">接收消息</param> /// <param name="onException">异常处理,返回true则会重新消费</param> public SimpleConsumer(string brokerUri, MQType type, string name, Action <ITextMessage> messageReceived, Func <Exception, bool> onException = null) { if (string.IsNullOrWhiteSpace(brokerUri)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(brokerUri)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(name)); } _messageReceived = messageReceived; _onException = onException; _connectionFactory = new ConnectionFactory(brokerUri); _destination = type.CreateDestination(name); }
//将日志发送到队列中 protected override ExeResEdm SendLogToQueue(object model, MQType mqType) { ExeResEdm exeResEdm = new ExeResEdm() { }; if (mqType == MQType.TraceLog)//是操作轨迹类数据 { var item = model as Log_OperateTrace; OperateLogQueue.Enqueue(item); return(exeResEdm); } else //是监控类数据 { var item = model as Log_SystemMonitorMQ; MonitorLogQueue.Enqueue(item); return(exeResEdm); } }
//队列消息生产 internal static ExeResEdm Send <T>(T model, MQType mqType) { lock (mqObj) { if (!bSendMsgUseMQ) { return(new ExeResEdm()); } string value = SerializerHelper.SerializeToString(model); var tt = RabbitSendDic[mqType]; try { return(tt.Send(value)); } catch (Exception ex) { LogCom.WriteExceptToFile(ex, "RabbitMQHelper.Send<T>"); return(new ExeResEdm() { ErrCode = 1, ExBody = ex, Module = "RabbitMQHelper.Send<T>" }); } } }
//将日志发送到队列中 protected abstract ExeResEdm SendLogToQueue(object model, MQType mqType);
//将日志保存到文件中 internal static ExeResEdm WriteLogToFile <T>(T model, MQType mqType) { return(WriteModelToFile(model, mqType.ToString(), FileType.File)); }
//将日志备份数据以json格式写入到文件中,以便以后读取到appender中 public static void WriteBackupLogToFile <T>(T model, MQType mqType) { WriteModelToFile(model, mqType.ToString(), FileType.Backup); }