/// <summary> /// 生产者(发送) /// </summary> /// <param name="queueName"></param> /// <param name="message"></param> /// <returns></returns> public bool Send <T>(string queueName, T message) where T : class { using (IConnection connection = CreateConnection) { using (IModel channel = connection.CreateModel()) { //设置交换器的类型 string ExchangeName = "Exchange_" + queueName; channel.ExchangeDeclare(ExchangeName, "direct", true, false, null); bool durable = true;//不会丢失队列,消息持久机制,持久化准备 channel.QueueDeclare(queueName, durable, false, false, null); //绑定消息队列,交换器,routingkey channel.QueueBind(queueName, ExchangeName, "Key_" + queueName); //消息持久化语句 IBasicProperties properties = channel.CreateBasicProperties(); properties.DeliveryMode = 2; properties.Persistent = true; byte[] bytes; bytes = SerializeObject <T>(message); channel.BasicPublish("", queueName, properties, bytes); } } LessLog.Info("发送成功,服务器IP为:" + rabbitConfig.HostName); return(true); }
/// <summary> /// /// </summary> /// <returns></returns> //public long Update() //{ // var result = Update<SysJobLog>(q => new SysJobLog() { Message = "修改Mess", Name = "修改的信息" }, q => q.JobLogId == 4 ); // return result; //} #region 所有查询 /// <summary> /// 同步查询示例 /// </summary> /// <param name="id"></param> /// <returns></returns> public SysJobLog GetEntity(int id) { SysJobLog entity = FirstOrDefault <SysJobLog>(q => q.JobLogId == 13); LessLog.Info("我是一条测试日志"); var json = typeof(EnumMemUserType).ToJson(); var des = EnumMemUserType.QQType.GetDescription(); return(entity); }
public void MessageTest() { string tagName = "消息标签";//自定义标签 var data = new ExcDataParam() { Name = "请求参数", Data = new { Id = 001, Name = "张三" } }; //自定义单个model var user = new ExcUserParam() { Id = "No0001", Name = "李廷礼", Email = "*****@*****.**", Description = "菁鲤汇高级开发工程师" }; //用户信息 var datas = new List <ExcDataParam>() //自定义列表数据 { new ExcDataParam() { Name = "请求参数", Data = new { Id = 002, Name = "李四" } }, new ExcDataParam() { Name = "返回结果", Data = new { Id = 003, Name = "王五" } } }; //日志等级:跟踪信息 LessLog.Trace("不带参数"); LessLog.Trace("带标签", tagName); LessLog.Trace("带用户&标签", user, tagName); LessLog.Trace("带自定义数据&标签", data, tagName); LessLog.Trace("带自定义数据&标签", datas, tagName); LessLog.Trace("带用户&自定义数据&标签", user, data, tagName); LessLog.Trace("带用户&自定义数据&标签", user, datas, tagName); //日志等级:调试信息 LessLog.Debug("不带参数"); LessLog.Debug("带标签", tagName); LessLog.Debug("带用户&标签", user, tagName); LessLog.Debug("带自定义数据&标签", data, tagName); LessLog.Debug("带自定义数据&标签", datas, tagName); LessLog.Debug("带用户&自定义数据&标签", user, data, tagName); LessLog.Debug("带用户&自定义数据&标签", user, datas, tagName); //日志等级:普通信息 LessLog.Info("不带参数"); LessLog.Info("带标签", tagName); LessLog.Info("带用户&标签", user, tagName); LessLog.Info("带自定义数据&标签", data, tagName); LessLog.Info("带自定义数据&标签", datas, tagName); LessLog.Info("带用户&自定义数据&标签", user, data, tagName); LessLog.Info("带用户&自定义数据&标签", user, datas, tagName); //日志等级:警告 LessLog.Warn("不带参数"); LessLog.Warn("带标签", tagName); LessLog.Warn("带用户&标签", user, tagName); LessLog.Warn("带自定义数据&标签", data, tagName); LessLog.Warn("带自定义数据&标签", datas, tagName); LessLog.Warn("带用户&自定义数据&标签", user, data, tagName); LessLog.Warn("带用户&自定义数据&标签", user, datas, tagName); //日志等级:致命的 LessLog.Fatal("不带参数"); LessLog.Fatal("带标签", tagName); LessLog.Fatal("带用户&标签", user, tagName); LessLog.Fatal("带自定义数据&标签", data, tagName); LessLog.Fatal("带自定义数据&标签", datas, tagName); LessLog.Fatal("带用户&自定义数据&标签", user, data, tagName); LessLog.Fatal("带用户&自定义数据&标签", user, datas, tagName); //日志等级:异常 LessLog.Error("不带参数"); LessLog.Error("带标签", tagName); LessLog.Error("带用户&标签", user, tagName); LessLog.Error("带自定义数据&标签", data, tagName); LessLog.Error("带自定义数据&标签", datas, tagName); LessLog.Error("带用户&自定义数据&标签", user, data, tagName); LessLog.Error("带用户&自定义数据&标签", user, datas, tagName); }
/// <summary> /// redis类库错误 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void MuxerInternalError(object sender, InternalErrorEventArgs e) { System.Console.WriteLine("InternalError:Message" + e.Exception.Message); LessLog.Info("InternalError:Message" + e.Exception.Message); }
/// <summary> /// 更改集群 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void MuxerHashSlotMoved(object sender, HashSlotMovedEventArgs e) { System.Console.WriteLine("HashSlotMoved:NewEndPoint" + e.NewEndPoint + ", OldEndPoint" + e.OldEndPoint); LessLog.Info("HashSlotMoved:NewEndPoint" + e.NewEndPoint + ", OldEndPoint" + e.OldEndPoint); }
/// <summary> /// 连接失败 , 如果重新连接成功你将不会收到这个通知 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void MuxerConnectionFailed(object sender, ConnectionFailedEventArgs e) { System.Console.WriteLine("重新连接:Endpoint failed: " + e.EndPoint + ", " + e.FailureType + (e.Exception == null ? "" : (", " + e.Exception.Message))); LessLog.Info("重新连接:Endpoint failed: " + e.EndPoint + ", " + e.FailureType + (e.Exception == null ? "" : (", " + e.Exception.Message))); }
/// <summary> /// 重新建立连接之前的错误 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void MuxerConnectionRestored(object sender, ConnectionFailedEventArgs e) { System.Console.WriteLine("ConnectionRestored: " + e.EndPoint); LessLog.Info("ConnectionRestored: " + e.EndPoint); }
/// <summary> /// 发生错误时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void MuxerErrorMessage(object sender, RedisErrorEventArgs e) { System.Console.WriteLine("ErrorMessage: " + e.Message); LessLog.Info("ErrorMessage: " + e.Message); }
/// <summary> /// 配置更改时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void MuxerConfigurationChanged(object sender, EndPointEventArgs e) { System.Console.WriteLine("Configuration changed: " + e.EndPoint); LessLog.Info("Configuration changed: " + e.EndPoint); }