コード例 #1
0
 public void Dispose()
 {
     eventStorage.Dispose();
 }
コード例 #2
0
ファイル: EventRepositoryBase.cs プロジェクト: mer2/octopus
        protected EventMessageHeader[] PopMessagesFromSubscribeQueueBatch(IEventStorage storage, string queueName, int count)
        {
            var length = count;
            var result = storage.Pipeline(s => {
                while (--length >= 0)
                {
                    s.RightPop(queueName);
                }
            });
            var keys       = new List <string>();
            var headerKeys = new List <string>();
            var bodyKeys   = new List <string>();

            foreach (var bytes in result)
            {
                if (!(bytes is byte[]))
                {
                    continue;
                }
                var msgKey = (byte[])bytes;
                var key    = msgKey.ToGuidString();
                keys.Add(key);
                headerKeys.Add(this.MessageHeaderPrefix + key);
                bodyKeys.Add(this.MessagePrefix + key);
            }
            if (keys.Count <= 0)
            {
                return(null);
            }
            storage.Pipeline(s => keys.ForEach(k => s.Decrement(this.MessageRefPrefix + k)));

            result = storage.Pipeline(s => {
                s.MultiGet(headerKeys.ToArray());
                s.MultiGet(bodyKeys.ToArray());
            });
            storage.Dispose();

            if (result == null)
            {
                return(null);
            }
            var objects = result.ToArray();

            if (objects.Length < 2)
            {
                return(null);
            }

            var headerBytes = (byte[][])objects[0];
            var bodyBytes   = (byte[][])objects[1];

            if (headerBytes == null || headerBytes.Length <= 0)
            {
                return(null);
            }
            if (bodyBytes == null || bodyBytes.Length != headerBytes.Length)
            {
                return(null);
            }

            var list = new List <EventMessageHeader>();

            for (var i = 0; i < headerBytes.Length; i++)
            {
                var bytes  = headerBytes[i];
                var header = this.Serializer.Deserialize <EventMessageHeader>(bytes, null);
                if (header == null)
                {
                    continue;
                }
                bytes = bodyBytes[i];
                var body = this.Serializer.Deserialize <EventMessage>(bytes, null);
                if (body.MessageGuid != header.MessageGuid)
                {
                    continue;
                }
                header.Message = body;
                list.Add(header);
            }
            return(list.ToArray());
        }