Ver código fonte

tweak database configuration name to ‘DatabaseName’

master
Savorboard 6 anos atrás
pai
commit
308539032b
8 arquivos alterados com 34 adições e 20 exclusões
  1. +20
    -6
      src/DotNetCore.CAP.MongoDB/CAP.MongoDBOptions.cs
  2. +1
    -1
      src/DotNetCore.CAP.MongoDB/CapPublisher.cs
  3. +2
    -2
      src/DotNetCore.CAP.MongoDB/MongoDBCollectProcessor.cs
  4. +1
    -1
      src/DotNetCore.CAP.MongoDB/MongoDBMonitoringApi.cs
  5. +4
    -4
      src/DotNetCore.CAP.MongoDB/MongoDBStorage.cs
  6. +1
    -1
      src/DotNetCore.CAP.MongoDB/MongoDBStorageConnection.cs
  7. +1
    -1
      src/DotNetCore.CAP.MongoDB/MongoDBStorageTransaction.cs
  8. +4
    -4
      src/DotNetCore.CAP.MongoDB/MongoDBUtil.cs

+ 20
- 6
src/DotNetCore.CAP.MongoDB/CAP.MongoDBOptions.cs Ver arquivo

@@ -5,16 +5,30 @@ namespace DotNetCore.CAP.MongoDB
{
public class MongoDBOptions
{
public const string DefaultDatabase = "Cap";
/// <summary>
/// Gets or sets the database name to use when creating database objects.
/// Default value: "cap"
/// </summary>
public string DatabaseName { get; set; } = "cap";

/// <summary>
/// Gets or sets the database to use when creating database objects.
/// Default is <see cref="DefaultDatabase" />.
/// MongoDB database connection string.
/// Default value: "mongodb://localhost:27017"
/// </summary>
public string Database { get; set; } = DefaultDatabase;
public string DatabaseConnection { get; set; } = "mongodb://localhost:27017";

public string ReceivedCollection { get; } = "Received";
/// <summary>
/// MongoDB received message collection name.
/// Default value: "received"
/// </summary>
public string ReceivedCollection { get; set; } = "cap.received";

/// <summary>
/// MongoDB published message collection name.
/// Default value: "published"
/// </summary>
public string PublishedCollection { get; set; } = "cap.published";

public string PublishedCollection { get; } = "Published";
internal const string CounterCollection = "cap.counter";
}
}

+ 1
- 1
src/DotNetCore.CAP.MongoDB/CapPublisher.cs Ver arquivo

@@ -28,7 +28,7 @@ namespace DotNetCore.CAP.MongoDB
: base(logger, dispatcher)
{
_options = options;
_database = client.GetDatabase(_options.Database);
_database = client.GetDatabase(_options.DatabaseName);
ServiceProvider = provider;
}



+ 2
- 2
src/DotNetCore.CAP.MongoDB/MongoDBCollectProcessor.cs Ver arquivo

@@ -23,13 +23,13 @@ namespace DotNetCore.CAP.MongoDB
{
_options = options;
_logger = logger;
_database = client.GetDatabase(_options.Database);
_database = client.GetDatabase(_options.DatabaseName);
}

public async Task ProcessAsync(ProcessingContext context)
{
_logger.LogDebug(
$"Collecting expired data from collection [{_options.Database}].[{_options.PublishedCollection}].");
$"Collecting expired data from collection [{_options.PublishedCollection}].");

var publishedCollection = _database.GetCollection<CapPublishedMessage>(_options.PublishedCollection);
var receivedCollection = _database.GetCollection<CapReceivedMessage>(_options.ReceivedCollection);


+ 1
- 1
src/DotNetCore.CAP.MongoDB/MongoDBMonitoringApi.cs Ver arquivo

@@ -22,7 +22,7 @@ namespace DotNetCore.CAP.MongoDB
var mongoClient = client ?? throw new ArgumentNullException(nameof(client));
_options = options ?? throw new ArgumentNullException(nameof(options));

_database = mongoClient.GetDatabase(_options.Database);
_database = mongoClient.GetDatabase(_options.DatabaseName);
}

public StatisticsDto GetStatistics()


+ 4
- 4
src/DotNetCore.CAP.MongoDB/MongoDBStorage.cs Ver arquivo

@@ -46,7 +46,7 @@ namespace DotNetCore.CAP.MongoDB
return;
}

var database = _client.GetDatabase(_options.Database);
var database = _client.GetDatabase(_options.DatabaseName);
var names = (await database.ListCollectionNamesAsync(cancellationToken: cancellationToken))?.ToList();

if (!names.Any(n => n == _options.ReceivedCollection))
@@ -60,10 +60,10 @@ namespace DotNetCore.CAP.MongoDB
cancellationToken: cancellationToken);
}

if (names.All(n => n != "Counter"))
if (names.All(n => n != MongoDBOptions.CounterCollection))
{
await database.CreateCollectionAsync("Counter", cancellationToken: cancellationToken);
var collection = database.GetCollection<BsonDocument>("Counter");
await database.CreateCollectionAsync(MongoDBOptions.CounterCollection, cancellationToken: cancellationToken);
var collection = database.GetCollection<BsonDocument>(MongoDBOptions.CounterCollection);
await collection.InsertManyAsync(new[]
{
new BsonDocument {{"_id", _options.PublishedCollection}, {"sequence_value", 0}},


+ 1
- 1
src/DotNetCore.CAP.MongoDB/MongoDBStorageConnection.cs Ver arquivo

@@ -22,7 +22,7 @@ namespace DotNetCore.CAP.MongoDB
_capOptions = capOptions;
_options = options;
_client = client;
_database = _client.GetDatabase(_options.Database);
_database = _client.GetDatabase(_options.DatabaseName);
}

public bool ChangePublishedState(int messageId, string state)


+ 1
- 1
src/DotNetCore.CAP.MongoDB/MongoDBStorageTransaction.cs Ver arquivo

@@ -17,7 +17,7 @@ namespace DotNetCore.CAP.MongoDB
public MongoDBStorageTransaction(IMongoClient client, MongoDBOptions options)
{
_options = options;
_database = client.GetDatabase(options.Database);
_database = client.GetDatabase(options.DatabaseName);
_session = client.StartSession();
_session.StartTransaction();
}


+ 4
- 4
src/DotNetCore.CAP.MongoDB/MongoDBUtil.cs Ver arquivo

@@ -19,10 +19,10 @@ namespace DotNetCore.CAP.MongoDB
IClientSessionHandle session = null)
{
//https://www.tutorialspoint.com/mongodb/mongodb_autoincrement_sequence.htm
var collection = database.GetCollection<BsonDocument>("Counter");
var collection = database.GetCollection<BsonDocument>(MongoDBOptions.CounterCollection);

var updateDef = Builders<BsonDocument>.Update.Inc("sequence_value", 1);
var filter = new BsonDocument {{"_id", collectionName}};
var filter = new BsonDocument { { "_id", collectionName } };

BsonDocument result;
if (session == null)
@@ -45,9 +45,9 @@ namespace DotNetCore.CAP.MongoDB
public int GetNextSequenceValue(IMongoDatabase database, string collectionName,
IClientSessionHandle session = null)
{
var collection = database.GetCollection<BsonDocument>("Counter");
var collection = database.GetCollection<BsonDocument>(MongoDBOptions.CounterCollection);

var filter = new BsonDocument {{"_id", collectionName}};
var filter = new BsonDocument { { "_id", collectionName } };
var updateDef = Builders<BsonDocument>.Update.Inc("sequence_value", 1);

var result = session == null


Carregando…
Cancelar
Salvar