예제 #1
0
 public IAOPResult PushToSubscribeQueue(string queueName, EventMessageHeader header)          //新消息分发到各个订阅队列
 {
     using (var storage = this.GetStorage(this.MainStorageName)) {
         storage.Pipeline(s => {
             s.LeftPush(this.SubscriberQueuePrefix + queueName, header.GetMessageKey()); //把消息ID入列
             s.Increment(this.MessageRefPrefix + header.MessageGuid);                    //增加消息的引用数
         });
     }
     return(AOPResult.Success());
 }
예제 #2
0
        public IAOPResult PushToMainQueue(EventMessageHeader header)
        {
            var message = header.Message; header.Message = null;

            this.Redis.Set(this.RedisDb, this.MessagePrefix + message.MessageGuid, message.SerializeToBytes());
            this.Redis.Set(this.RedisDb, this.MessageHeaderPrefix + message.MessageGuid, header.SerializeToBytes());
            var messageKey = header.GetMessageKey();

            this.Redis.LeftPush(this.RedisDb, this.PublishQueueName, header.GetMessageKey());
            this.Redis.Publish(this.NotifyQueueName, messageKey);
            return(AOPResult.Success());
        }
예제 #3
0
 //新消息分发到各个订阅队列
 public IAOPResult PushToSubscribeQueues(EventMessageHeader header, string[] queueNames)
 {
     if (queueNames != null && queueNames.Length > 0)
     {
         using (var storage = this.GetStorage(this.MainStorageName)) {
             storage.Pipeline(s => {
                 foreach (var queueName in queueNames)
                 {
                     s.LeftPush(this.SubscriberQueuePrefix + queueName, header.GetMessageKey());          //把消息ID入列
                     s.Increment(this.MessageRefPrefix + header.MessageGuid);                             //增加消息的引用数
                 }
                 //保存此消息分发到哪些订阅队列,以供排查分析
                 s.Set(this.MessageDispatchPrefix + header.MessageGuid, this.Encoding.GetBytes(string.Join(",", queueNames)));
             });
         }
     }
     return(AOPResult.Success());
 }
예제 #4
0
        public IAOPResult PushToMainQueue(EventMessageHeader header)          //新消息发布到主队列
        {
            var message = header.Message; header.Message = null;

            using (var storage = this.GetStorage(this.MainStorageName)) {
                storage.Pipeline(s => {
                    //保存消息主体和消息头
                    s.MultiSet(new Dictionary <string, byte[]> {
                        { this.MessagePrefix + message.MessageGuid, this.Serializer.Serialize(message, null) },
                        { this.MessageHeaderPrefix + message.MessageGuid, this.Serializer.Serialize(header, null) },
                    });
                    var messageKey = header.GetMessageKey();
                    s.LeftPush(this.PublishQueueName, messageKey);                  //把消息ID入列到消息队列里
                    s.Publish(this.NotifyQueueName, messageKey);                    //通知分发器有新消息过来了
                });
            }
            return(AOPResult.Success());
        }
예제 #5
0
        //分发一条消息到各个订阅队列
        protected void DispatchMessage(IEventRepository repository, List <EventMessage> list, EventMessageHeader message)
        {
            var subs = EventClientService.GetDispatchedSubscribers(message.Message, list);            //消息被分发到的订阅队列

            if (subs.Count > 0)
            {
                var names = subs.Select(x => x.ChannelID).ToArray();
                repository.PushToSubscribeQueues(message, names);                //分发到订阅队列
                foreach (var subscriber in subs)
                {
                    var sub = subscriber;
                    Task.Factory.StartNew(() => this.Callee.SendMessage(repository, sub));                    //异步主动推送消息给调用方
                }
            }
        }
예제 #6
0
 public IAOPResult PushToSubscribeQueue(string queueName, EventMessageHeader header)
 {
     this.Redis.LeftPush(this.RedisDb, this.SubscriberQueuePrefix + queueName, header.GetMessageKey());
     this.Redis.Increment(this.RedisDb, this.MessageRefPrefix + header.MessageGuid);
     return(AOPResult.Success());
 }
예제 #7
0
 IAOPResult IEventRepository.PushToSubscribeQueues(EventMessageHeader message, string[] queueNames)
 {
     return(this.InvokeMethodSafety(() => this.PushToSubscribeQueues(message, queueNames)));
 }
예제 #8
0
 IAOPResult IEventRepository.PushToSubscribeQueue(string queueName, EventMessageHeader message)
 {
     return(this.InvokeMethodSafety(() => this.PushToSubscribeQueue(queueName, message)));
 }
예제 #9
0
 IAOPResult IEventRepository.PushToMainQueue(EventMessageHeader message)
 {
     return(this.InvokeMethodSafety(() => this.PushToMainQueue(message)));
 }