/// <summary> /// 发布延迟消息 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="msgs">消息</param> /// <param name="config">路由配置</param> /// <param name="delay">延迟时间</param> /// <param name="persistent">消息是否持久化</param> /// <returns>是否发生成功</returns> public virtual bool PublishDelay <T>(List <T> msgs, PubMsgConfig config, TimeSpan delay, bool persistent = false) { if (config == null) { throw new ArgumentNullException(nameof(config)); } return(this.PublishDelay(msgs, config.RoutingKey, delay, config.Exchange, persistent)); }
/// <summary> /// 发布消息 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="msg">消息</param> /// <param name="config">路由配置</param> /// <param name="expire">消息过期时间</param> /// <param name="persistent">消息是否持久化</param> /// <returns></returns> public virtual bool Publish <T>(T msg, PubMsgConfig config, TimeSpan?expire = null, bool persistent = false) { if (config == null) { throw new ArgumentNullException(nameof(config)); } return(this.Publish(msg, config.RoutingKey, expire, config.Exchange, persistent)); }
/// <summary> /// 获取配置生产消息配置 /// </summary> /// <param name="name">配置name</param> /// <returns></returns> public PubMsgConfig GetPubMsgConfig(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } PubMsgConfig m = null; return(pubMsgDic.TryGetValue(name, out m) ? m.Copy() : null); }
private void LoadPubMsg(XmlElement rootElement) { var nodes = rootElement.SelectNodes("PubMsg/Key"); pubMsgDic = new Dictionary <string, PubMsgConfig>(nodes.Count); foreach (XmlNode node in nodes) { if (node is XmlElement) { XmlElement element = node as XmlElement; string s = element.GetAttribute("name"); if (string.IsNullOrEmpty(s)) { throw new ArgumentNullException("PubMsg config is null!"); } if (pubMsgDic.ContainsKey(s)) { throw new ArgumentException($"PubMsg config ({s}) is repeat!"); } var m = new PubMsgConfig() { Name = s }; s = element.GetAttribute("routingKey"); if (string.IsNullOrEmpty(s)) { throw new ArgumentNullException($"PubMsg ({s}) routingKey config is null!"); } m.RoutingKey = s; s = element.GetAttribute("exchange"); if (!string.IsNullOrEmpty(s)) { m.Exchange = s; } s = element.GetAttribute("isRoutingKeyParam"); if (!string.IsNullOrEmpty(s)) { m.IsRoutingKeyParam = s.ToLower() == "true" || s == "1"; } pubMsgDic.Add(m.Name, m); } } }