示例#1
0
        public async Task <IAsyncCursor <BsonDocument> > GetCursor(ResumeToken resumeToken,
                                                                   IEnumerable <string> collections,
                                                                   CancellationToken cancellationToken)
        {
            BsonValue ts;

            if (resumeToken.Token != null)
            {
                ts = resumeToken.Token["ts"];
            }
            else
            {
                var operation = await operations
                                .Find(new BsonDocument())
                                .Sort(Builders <BsonDocument> .Sort.Descending("$natural"))
                                .FirstAsync(cancellationToken);

                ts = operation["ts"];
            }

            var filter = builder.And(
                builder.In("op", new[] { "i", "u", "d" }),
                builder.Gt("ts", ts),
                builder.In("ns", collections.Select(collectionName => $"{databaseName}.{collectionName}")),
                builder.Exists("fromMigrate", false)
                );

            var options = new FindOptions <BsonDocument>
            {
                CursorType = CursorType.TailableAwait, NoCursorTimeout = true, OplogReplay = true
            };

            return(await operations.FindAsync(filter, options, cancellationToken));
        }
示例#2
0
        private async Task <Unit> SaveEvents(ICollection <BatchItem> items, ResumeToken resumeToken)
        {
            if (items.Any())
            {
                var last = items.Last();

                await events.InsertManyAsync(items.Select(item => item.Event));

                resumeToken.Token   = last.Token;
                resumeToken.Updated = last.WallClock;

                await tokens.Save(resumeToken);

                logger.Information("Published {@count} event(s).", items.Count);
            }

            return(Unit.Default);
        }