コード例 #1
0
        public override bool SendMessage(MQMessage message, MQConnParms parms)
        {
            using (var channel = conn.CreateModel())
            {
                if (!ExchangeNames.Contains(parms.MQExchange))
                {
                    ExchangeNames.Add(parms.MQExchange);
                    channel.ExchangeDeclare(parms.MQExchange, "topic", true, false, null);
                    channel.BasicQos(0, 1, false);  // 不要在同一时间给一个工作者发送多于1个的消息
                }
                JsonSerializer serializer = new JsonSerializer();
                var            sw         = new StringWriter();
                serializer.Serialize(new JsonTextWriter(sw), message.Messages);

                IBasicProperties propertie;
                propertie            = channel.CreateBasicProperties();
                propertie.Persistent = true;    // 消息需要落地
                propertie.Headers    = new Dictionary <string, object>();
                Messages.ForEach(o =>
                {
                    propertie.Headers.Add(o.Key, o.Value(message));
                });

                channel.BasicPublish(parms.MQExchange, parms.MQRoutingKey, propertie, Encoding.UTF8.GetBytes(sw.GetStringBuilder().ToString()));
                channel.Close();
            }

            return(true);
        }
コード例 #2
0
 public override bool SendMessage(MQMessage message, MQConnParms parms)
 {
     throw new NotImplementedException();
 }