Beispiel #1
0
        /**
         * <summary>
         * Package protected member to read the mesage from a DataOutput stream.
         * </summary>
         *
         * <param name="input">			The stream from which the data is to be read</param>
         * <param name="retrievebody">  A flag indicating the body of the message should
         *                              be retrieved.</param>
         *
         *
         * <exception cref="Exception"> In the case that the stream experiences an error
         *                              while reading data.</exception>
         */
        internal void Read(BinaryReader input, bool retrievebody)
        {
            // Make sure that if this object is being reused we don't over write the UUID
            (messageID = new UUID()).Read(input);
            messageClass    = (MessageClassEnum)input.ReadByte();
            messagePriority = (MessagePriorityEnum)input.ReadByte();

            byte[] tmp = input.ReadBytes(Safmq.MSGLBL_LENGTH);
            label = new string(Encoding.UTF8.GetChars(tmp, 0, ioutil.length(tmp)));

            timeStamp         = input.ReadInt32();
            timeToLiveSeconds = input.ReadInt32();
            ttlErrorWanted    = input.ReadByte();

            tmp = input.ReadBytes(Safmq.QNAME_LENGTH);
            this.responseQueueName = new string(Encoding.UTF8.GetChars(tmp, 0, ioutil.length(tmp)));

            // Make sure that if this object is being reused we don't over write the UUID
            (reciptID = new UUID()).Read(input);

            bodyType = (BodyTypeEnum)input.ReadByte();
            bodySize = input.ReadInt32();

            if (bodySize > 0)
            {
                body = new MemoryStream(input.ReadBytes(bodySize));
            }
        }
Beispiel #2
0
        public List <NotifyMessage> GetList(MessagePriorityEnum mesPrvEnm, string messTypeEnm)
        {
            Stopwatch watch = Stopwatch.StartNew();

            watch.Start();
            List <NotifyMessage> list = new List <NotifyMessage>();
            int count = 1000;

            for (int i = 0; i < count; i++)
            {
                NotifyMessage mess = new NotifyMessage()
                {
                    MessageId       = IdentityGenerator.New(),
                    AppId           = "11011",
                    MessagePriority = mesPrvEnm,
                    MessageKey      = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + mesPrvEnm.ToString() + "_" + i.ToString(),
                    MessageType     = messTypeEnm.ToString(),
                    NotifyData      = "a=1&b=2",
                    SourceFrom      = "test",
                    ClientIP        = "127.0.0.1",
                    CreateTime      = DateTime.Now
                };
                list.Add(mess);
            }

            watch.Stop();
            long min = watch.ElapsedMilliseconds;

            return(list);
        }
        /// <summary>
        /// Gets the next message of the specified priority from the queue
        /// </summary>
        /// <param name="priority">The priority of the message to dequeue</param>
        /// <returns>A message, or null if there are no messages of the specified priority in the queue</returns>
        public Message Dequeue(MessagePriorityEnum priority)
        {
            // Select the sub-queue based on specified priority
            Queue<Message> queue = null;
            switch (priority)
            {
                case MessagePriorityEnum.Low:
                    queue = lowQueue;
                    break;
                case MessagePriorityEnum.Normal:
                    queue = midQueue;
                    break;
                case MessagePriorityEnum.High:
                    queue = highQueue;
                    break;
            }

            // Dequeue a message from the selected queue, if there is one
            Message m = null;
            if (queue.Count > 0)
            {
                lock(locker)
                    m = queue.Dequeue();
            }
            return m;
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TerraGrafMessageBase"/> class.
 /// </summary>
 /// <param name="senderId">The sender id.</param>
 /// <param name="targetId">The target id.</param>
 /// <param name="messageCode">The message code.</param>
 /// <param name="messageId">The message id.</param>
 /// <param name="priority">The priority.</param>
 /// <param name="messageType">Type of the message.</param>
 protected TerraGrafMessageBase(string senderId, string targetId, MessageCodeEnum messageCode, long messageId,
                                MessagePriorityEnum priority, MessageTypeEnum messageType)
     : base(senderId, messageId, messageCode)
 {
     this.mPriority    = priority;
     this.mMessageType = messageType;
     this.mTargetId    = (targetId == null ? string.Empty : targetId);
 }
Beispiel #5
0
        public void Subscribe(RabbitMQBus rabbitMQ, MessagePriorityEnum priority, Action <NotifyMessage> handler)
        {
            try
            {
                string topic = priority.ToString().ToUpper();
                rabbitMQ.Bus.Subscribe(QueueDic[topic], (body, props, info) => Task.Factory.StartNew(() =>
                {
                    MetricsKeys.RabbitMQ_Subscribe.MeterMark("Success");
                    if (DataCache.Add(props.MessageId, 1, DateTime.Now.AddMinutes(10)))
                    {
                        try
                        {
                            if (props.Type == "M")
                            {
#if DEBUG
                                System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew();
#endif
                                List <NotifyMessage> list = JsonConvert.DeserializeObject <List <NotifyMessage> >(Encoding.UTF8.GetString(body), serializerSettings);
                                for (int i = 0; i < list.Count; i++)
                                {
                                    handler(list[i]);
                                }
#if DEBUG
                                watch.Stop();
                                Process.Debug("订阅消息", "Consume", string.Format("数据模式:【{0}】,条数:【{1}】,耗时:【{2}】", props.Type, list.Count, watch.ElapsedMilliseconds), "");
#endif
                            }
                            else if (props.Type == "S")
                            {
                                handler(JsonConvert.DeserializeObject <NotifyMessage>(Encoding.UTF8.GetString(body), serializerSettings));
#if DEBUG
                                Process.Debug("订阅消息", "Consume", string.Format("数据模式:【{0}】,条数:【{1}】", props.Type, 1), "");
#endif
                            }
                        }
                        catch (Exception ex)
                        {
                            m_logger.Error("处理消息发生异常:" + ex.GetString());
                        }
                    }
                    else
                    {
                        RepeatMessageDic[props.MessageId] = RepeatMessageDic[props.MessageId] + 1;
                        ComsumeMessage(props.MessageId, RepeatMessageDic[props.MessageId]);
                    }
                }));
            }
            catch (Exception ex)
            {
                MetricsKeys.RabbitMQ_Subscribe.MeterMark("Error");
                m_logger.Error("订阅消息发生异常:" + ex.GetString());
                throw new RabbitMQException("订阅消息发生异常", ex);
            }
        }
Beispiel #6
0
 public void Publisher(RabbitMQBus rabbitMQ, MessagePriorityEnum priority, List <NotifyMessage> messageList)
 {
     try
     {
         string            topic = priority.ToString().ToUpper();
         var               body  = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(messageList, serializerSettings));
         MessageProperties prop  = new MessageProperties()
         {
             AppId     = ConfigurationAppSetting.AppId,
             Priority  = (byte)priority,
             MessageId = messageList[0].MessageId,
             Type      = "M"
         };
         rabbitMQ.Bus.OpenPublishChannel().Publish(ExchangeDic[topic], "", prop, body);
         MetricsKeys.RabbitMQ_Publish.MeterMark("Success");
     }
     catch (Exception ex)
     {
         MetricsKeys.RabbitMQ_Publish.MeterMark("Error");
         m_logger.Error("推送消息发生异常:" + ex.GetString());
         throw new RabbitMQException("推送消息发生异常", ex);
     }
 }
Beispiel #7
0
 public void Publisher(MessagePriorityEnum priority, List <NotifyMessage> messageList)
 {
     Publisher(RabbitMQBusMgr.Instance, priority, messageList);
 }
Beispiel #8
0
 public void Subscribe(MessagePriorityEnum priority, Action <NotifyMessage> handler)
 {
     Subscribe(RabbitMQBusMgr.Instance, priority, handler);
 }
Beispiel #9
0
 private void Subscribe(RabbitMQBus bus, MessagePriorityEnum priority)
 {
     Process.Debug("并行生成消息", "Subscribe", string.Format("开始订阅,消息优先级:【{0}】", priority.ToString()), "");
     RabbitMQBusiness.Instance.Subscribe(bus, priority, m_buildBus.Build);
 }
Beispiel #10
0
        /**
         * <summary>
         * Package protected member to read the mesage from a DataOutput stream.
         * </summary>
         *
         * <param name="input">			The stream from which the data is to be read</param>
         * <param name="retrievebody">  A flag indicating the body of the message should
         * 							    be retrieved.</param>
         *
         *
         * <exception cref="Exception"> In the case that the stream experiences an error
         *      						while reading data.</exception>
         */
        internal void Read(BinaryReader input, bool retrievebody)
        {
            // Make sure that if this object is being reused we don't over write the UUID
            (messageID = new UUID()).Read(input);
            messageClass = (MessageClassEnum)input.ReadByte();
            messagePriority = (MessagePriorityEnum)input.ReadByte();

            byte[] tmp = input.ReadBytes(Safmq.MSGLBL_LENGTH);
            label = new string(Encoding.UTF8.GetChars(tmp, 0, ioutil.length(tmp)));

            timeStamp = input.ReadInt32();
            timeToLiveSeconds = input.ReadInt32();
            ttlErrorWanted = input.ReadByte();

            tmp = input.ReadBytes(Safmq.QNAME_LENGTH);
            this.responseQueueName = new string(Encoding.UTF8.GetChars(tmp, 0, ioutil.length(tmp)));

            // Make sure that if this object is being reused we don't over write the UUID
            (reciptID = new UUID()).Read(input);

            bodyType = (BodyTypeEnum)input.ReadByte();
            bodySize = input.ReadInt32();

            if (bodySize > 0)
                body = new MemoryStream(input.ReadBytes(bodySize));
        }
Beispiel #11
0
 /// <summary>
 /// Creates a message with the specified action, target, sender, priority, and arguments
 /// </summary>
 /// <param name="action">The action for the reciever to perform</param>
 /// <param name="target">The destination of the message</param>
 /// <param name="sender">The sender of the message</param>
 /// <param name="priority">The priority of the message</param>
 /// <param name="arguments">The arguments to send with the message</param>
 public Message(string action, MessagePriorityEnum priority, List<object> arguments, string target, string sender)
     : this(action, priority, target, sender)
 {
     this.arguments = arguments;
 }
Beispiel #12
0
 /// <summary>
 /// Creates a message with the specified action, target, sender, and priority
 /// </summary>
 /// <param name="action">The action for the reciever to perform</param>
 /// <param name="target">The destination of the message</param>
 /// <param name="sender">The sender of the message</param>
 /// <param name="priority">The priority of the message</param>
 public Message(string action, MessagePriorityEnum priority, string target, string sender)
     : this(action, target, sender)
 {
     this.priority = priority;
 }
Beispiel #13
0
 /// <summary>
 /// Creates a message with the specified action, target, sender, priority, and arguments
 /// </summary>
 /// <param name="action">The action for the reciever to perform</param>
 /// <param name="target">The destination of the message</param>
 /// <param name="sender">The sender of the message</param>
 /// <param name="priority">The priority of the message</param>
 /// <param name="arguments">The arguments to send with the message</param>
 public Message(string action, MessagePriorityEnum priority, object[] arguments, string target, string sender)
     : this(action, priority, target, sender)
 {
     this.arguments.AddRange(arguments);
 }