@@ -25,18 +25,16 @@ namespace DotNetCore.CAP.MySql | |||
_options = options; | |||
_logger = logger; | |||
if (_options.DbContextType != null) | |||
{ | |||
IsUsingEF = true; | |||
_dbContext = (DbContext) ServiceProvider.GetService(_options.DbContextType); | |||
} | |||
if (_options.DbContextType == null) return; | |||
IsUsingEF = true; | |||
_dbContext = (DbContext) ServiceProvider.GetService(_options.DbContextType); | |||
} | |||
public async Task PublishAsync(CapPublishedMessage message) | |||
public Task PublishAsync(CapPublishedMessage message) | |||
{ | |||
using (var conn = new MySqlConnection(_options.ConnectionString)) | |||
{ | |||
await conn.ExecuteAsync(PrepareSql(), message); | |||
return conn.ExecuteAsync(PrepareSql(), message); | |||
} | |||
} | |||
@@ -64,12 +62,14 @@ namespace DotNetCore.CAP.MySql | |||
_logger.LogInformation("Published Message has been persisted in the database. name:" + message); | |||
} | |||
protected override async Task ExecuteAsync(IDbConnection dbConnection, IDbTransaction dbTransaction, | |||
protected override Task ExecuteAsync(IDbConnection dbConnection, IDbTransaction dbTransaction, | |||
CapPublishedMessage message) | |||
{ | |||
await dbConnection.ExecuteAsync(PrepareSql(), message, dbTransaction); | |||
dbConnection.ExecuteAsync(PrepareSql(), message, dbTransaction); | |||
_logger.LogInformation("Published Message has been persisted in the database. name:" + message); | |||
return Task.CompletedTask; | |||
} | |||
#region private methods | |||
@@ -32,11 +32,11 @@ namespace DotNetCore.CAP.PostgreSql | |||
} | |||
} | |||
public async Task PublishAsync(CapPublishedMessage message) | |||
public Task PublishAsync(CapPublishedMessage message) | |||
{ | |||
using (var conn = new NpgsqlConnection(_options.ConnectionString)) | |||
{ | |||
await conn.ExecuteAsync(PrepareSql(), message); | |||
return conn.ExecuteAsync(PrepareSql(), message); | |||
} | |||
} | |||
@@ -64,12 +64,14 @@ namespace DotNetCore.CAP.PostgreSql | |||
_logger.LogInformation("Published Message has been persisted in the database. name:" + message); | |||
} | |||
protected override async Task ExecuteAsync(IDbConnection dbConnection, IDbTransaction dbTransaction, | |||
protected override Task ExecuteAsync(IDbConnection dbConnection, IDbTransaction dbTransaction, | |||
CapPublishedMessage message) | |||
{ | |||
await dbConnection.ExecuteAsync(PrepareSql(), message, dbTransaction); | |||
dbConnection.ExecuteAsync(PrepareSql(), message, dbTransaction); | |||
_logger.LogInformation("Published Message has been persisted in the database. name:" + message); | |||
return Task.CompletedTask; | |||
} | |||
#region private methods | |||
@@ -38,8 +38,7 @@ namespace DotNetCore.CAP.RabbitMQ | |||
{ | |||
_maxSize = 0; | |||
IConnection context; | |||
while (_pool.TryDequeue(out context)) | |||
while (_pool.TryDequeue(out var context)) | |||
context.Dispose(); | |||
} | |||
@@ -42,14 +42,14 @@ namespace DotNetCore.CAP.RabbitMQ | |||
null, | |||
body); | |||
_logger.LogDebug($"rabbitmq topic message [{keyName}] has been published."); | |||
_logger.LogDebug($"RabbitMQ topic message [{keyName}] has been published."); | |||
} | |||
return Task.FromResult(OperateResult.Success); | |||
} | |||
catch (Exception ex) | |||
{ | |||
_logger.LogError( | |||
$"rabbitmq topic message [{keyName}] has benn raised an exception of sending. the exception is: {ex.Message}"); | |||
$"RabbitMQ topic message [{keyName}] has been raised an exception of sending. the exception is: {ex.Message}"); | |||
return Task.FromResult(OperateResult.Failed(ex, | |||
new OperateError | |||
@@ -25,18 +25,17 @@ namespace DotNetCore.CAP.SqlServer | |||
_logger = logger; | |||
_options = options; | |||
if (_options.DbContextType != null) | |||
{ | |||
IsUsingEF = true; | |||
_dbContext = (DbContext) ServiceProvider.GetService(_options.DbContextType); | |||
} | |||
if (_options.DbContextType == null) return; | |||
IsUsingEF = true; | |||
_dbContext = (DbContext) ServiceProvider.GetService(_options.DbContextType); | |||
} | |||
public async Task PublishAsync(CapPublishedMessage message) | |||
public Task PublishAsync(CapPublishedMessage message) | |||
{ | |||
using (var conn = new SqlConnection(_options.ConnectionString)) | |||
{ | |||
await conn.ExecuteAsync(PrepareSql(), message); | |||
return conn.ExecuteAsync(PrepareSql(), message); | |||
} | |||
} | |||
@@ -64,12 +63,14 @@ namespace DotNetCore.CAP.SqlServer | |||
_logger.LogInformation("Published Message has been persisted in the database. name:" + message); | |||
} | |||
protected override async Task ExecuteAsync(IDbConnection dbConnection, IDbTransaction dbTransaction, | |||
protected override Task ExecuteAsync(IDbConnection dbConnection, IDbTransaction dbTransaction, | |||
CapPublishedMessage message) | |||
{ | |||
await dbConnection.ExecuteAsync(PrepareSql(), message, dbTransaction); | |||
dbConnection.ExecuteAsync(PrepareSql(), message, dbTransaction); | |||
_logger.LogInformation("Published Message has been persisted in the database. name:" + message); | |||
return Task.CompletedTask; | |||
} | |||
#region private methods | |||