Exemple #1
0
        protected override Task ExecuteAsync(CapPublishedMessage message, ICapTransaction transaction,
                                             CancellationToken cancel = default(CancellationToken))
        {
            var insertOptions = new InsertOneOptions {
                BypassDocumentValidation = false
            };

            var collection = _client
                             .GetDatabase(_options.DatabaseName)
                             .GetCollection <PublishedMessage>(_options.PublishedCollection);

            var store = new PublishedMessage()
            {
                Id         = message.Id,
                Name       = message.Name,
                Content    = message.Content,
                Added      = message.Added,
                StatusName = message.StatusName,
                ExpiresAt  = message.ExpiresAt,
                Retries    = message.Retries,
                Version    = _options.Version,
            };

            if (NotUseTransaction)
            {
                return(collection.InsertOneAsync(store, insertOptions, cancel));
            }

            var dbTrans = (IClientSessionHandle)transaction.DbTransaction;

            return(collection.InsertOneAsync(dbTrans, store, insertOptions, cancel));
        }
Exemple #2
0
        public MediumMessage StoreMessage(string name, Message content, object dbTransaction = null)
        {
            var insertOptions = new InsertOneOptions {
                BypassDocumentValidation = false
            };

            var message = new MediumMessage
            {
                DbId      = content.GetId(),
                Origin    = content,
                Content   = _serializer.Serialize(content),
                Added     = DateTime.Now,
                ExpiresAt = null,
                Retries   = 0
            };

            var collection = _database.GetCollection <PublishedMessage>(_options.Value.PublishedCollection);

            var store = new PublishedMessage
            {
                Id         = long.Parse(message.DbId),
                Name       = name,
                Content    = message.Content,
                Added      = message.Added,
                StatusName = nameof(StatusName.Scheduled),
                ExpiresAt  = message.ExpiresAt,
                Retries    = message.Retries,
                Version    = _options.Value.Version
            };

            if (dbTransaction == null)
            {
                collection.InsertOne(store, insertOptions);
            }
            else
            {
                var dbTrans = dbTransaction as IClientSessionHandle;
                collection.InsertOne(dbTrans, store, insertOptions);
            }

            return(message);
        }