Beispiel #1
0
        public void UpdateItem(TaskMessage item)
        {
            Dictionary <string, object> holder = item.GetHolder();
            object id = holder["_id"];

            if (id == null || !(id is ObjectId))
            {
                throw new Exception("_id of queue element is missing");
            }

            BsonObjectId objid = new BsonObjectId((ObjectId)id);

            holder.Remove("_id");

            MongoMessage msg = new MongoMessage
            {
                ExtraElements = holder,
                id            = objid
            };

            //var result = Collection.Save(msg, new MongoInsertOptions() { WriteConcern = new WriteConcern() { Journal = true } });
            var result = Collection.Save(msg);

            if (!result.Ok)
            {
                throw new Exception("error in update to mongo queue: " + result.ToJson());
            }
        }
Beispiel #2
0
        public void Push(TaskMessage item)
        {
            CheckConnection();

            //WriteConcernResult result = Collection.Insert(new BsonDocument(item.GetHolder()), new MongoInsertOptions() { WriteConcern = new WriteConcern() { Journal = true } });
            //WriteConcernResult result = Collection.Insert(new MongoMessage { ExtraElements = item.GetHolder() }, new MongoInsertOptions() { WriteConcern = new WriteConcern() { Journal = true } });
            WriteConcernResult result = Collection.Insert(new MongoMessage {
                ExtraElements = item.GetHolder()
            });

            // TODO: QueueOverflowException

            if (!result.Ok)
            {
                throw new Exception("error in push to mongo queue: " + result.ToJson());
            }
        }
Beispiel #3
0
        public void UpdateItem(TaskMessage item)
        {
            Dictionary <string, object> holder = item.GetHolder();
            object id = holder["__original"];

            if (id == null || !(id is ValueMap <string, object>))
            {
                throw new Exception("__original of queue element is missing");
            }
            ValueMap <string, object> orig = (ValueMap <string, object>)id;

            holder.Remove("__original");
            lock (MessageQueue)
            {
                if (!MessageQueue.Remove(orig))
                {
                    throw new Exception("can't update element in queue");
                }
                this.Push(item);
            }
        }