Esempio n. 1
0
        public DeleteError DeleteMessage(string queueName, long messageId, string popReceipt)
        {
            using (var dc = new Data.MessageDataContext())
            {
                var msg = dc.Messages.First(m => m.Id == messageId);
                if (msg == null) return DeleteError.NotFound;
                if (msg.Queue != queueName) return DeleteError.NotFound;
                if (msg.PopReceipt.GetValueOrDefault().ToString("N") != popReceipt) return DeleteError.LostOwnership;

                dc.Messages.DeleteOnSubmit(msg);
                dc.SubmitChanges();
            }

            return DeleteError.Ok;
        }
Esempio n. 2
0
        public Message[] GetMessages(string queueName, int numberOfMessages, TimeSpan visibilityTimeout)
        {
            Utils.Initialize();

            using (var dc = new Data.MessageDataContext())
            {
                var now = DateTime.UtcNow;

                var qry = dc.ExecuteQuery<Data.Message>(Utils.GetMessageSql,
                    numberOfMessages,
                    Guid.NewGuid(),
                    now + visibilityTimeout,
                    now,
                    queueName);

                return qry.Select(m => m.ToMessage()).ToArray();
            }
        }
Esempio n. 3
0
        public void PutMessage(string queueName, Message message, TimeSpan timeToLive)
        {
            var msg = new Data.Message();
            msg.Queue = queueName;
            if (message.Content != null)
                msg.Content = message.Content;

            using (var dc = new Data.MessageDataContext())
            {
                dc.Messages.InsertOnSubmit(msg);
                dc.SubmitChanges();
            }
        }
Esempio n. 4
0
        public Message[] PeekMessages(string queueName, int numberOfMessages)
        {
            Utils.Initialize();

            using (var dc = new Data.MessageDataContext())
            {
                var qry = dc.ExecuteQuery<Data.Message>(Utils.PeekMessageSql,
                    numberOfMessages,
                    queueName);

                return qry.Select(m => m.ToMessage()).Select(m => { m.PopReceipt = null; return m; }).ToArray();
            }
        }
Esempio n. 5
0
File: Utils.cs Progetto: yaq/yaq
        internal static void Initialize()
        {
            if (_initialized) return;

            lock (_sync)
            {
                if (_initialized) return;

                var dc = new Data.MessageDataContext();
                var mt = dc.Mapping.GetMetaType(typeof(Data.Message));

                var queue = mt.GetMetaDataMember(m => m.Queue);
                var takenTill = mt.GetMetaDataMember(m => m.TakenTill);
                var popReceipt = mt.GetMetaDataMember(m => m.PopReceipt);
                var id = mt.GetMetaDataMember(m => m.Id);

                PeekMessageSql = String.Format("select top({{0}}) * from {0} where [{1}] = {{1}} order by [{2}]",
                    mt.Table.TableName,
                    queue.MappedName,
                    id.MappedName);

                GetMessageSql = String.Format(@"
                    update top({{0}}) {0}
                    set [{1}] = {{1}}, [{2}] = {{2}}
                        output inserted.*
                    from {0} with(readpast, index([Message.IX.ByQueue]))
                    where
                        ([{2}] is null or [{2}] <= {{3}})
                        and [{3}] = {{4}}",
                        mt.Table.TableName,
                        popReceipt.MappedName,
                        takenTill.MappedName,
                        queue.MappedName);

                _initialized = true;
            }
        }