Publish<T> will support it.master
@@ -38,25 +38,11 @@ namespace DotNetCore.CAP.MySql | |||
} | |||
} | |||
public void Publish(string name, string content) | |||
{ | |||
CheckIsUsingEF(name); | |||
PublishCore(name, content); | |||
} | |||
public Task PublishAsync(string name, string content) | |||
{ | |||
CheckIsUsingEF(name); | |||
return PublishCoreAsync(name, content); | |||
} | |||
public void Publish<T>(string name, T contentObj) | |||
{ | |||
CheckIsUsingEF(name); | |||
var content = Helper.ToJson(contentObj); | |||
var content = Serialize(contentObj); | |||
PublishCore(name, content); | |||
} | |||
@@ -65,36 +51,18 @@ namespace DotNetCore.CAP.MySql | |||
{ | |||
CheckIsUsingEF(name); | |||
var content = Helper.ToJson(contentObj); | |||
var content = Serialize(contentObj); | |||
return PublishCoreAsync(name, content); | |||
} | |||
public void Publish(string name, string content, IDbConnection dbConnection, IDbTransaction dbTransaction = null) | |||
{ | |||
CheckIsAdoNet(name); | |||
PrepareConnection(dbConnection, ref dbTransaction); | |||
PublishWithTrans(name, content, dbConnection, dbTransaction); | |||
} | |||
public Task PublishAsync(string name, string content, IDbConnection dbConnection, IDbTransaction dbTransaction = null) | |||
{ | |||
CheckIsAdoNet(name); | |||
PrepareConnection(dbConnection, ref dbTransaction); | |||
return PublishWithTransAsync(name, content, dbConnection, dbTransaction); | |||
} | |||
public void Publish<T>(string name, T contentObj, IDbConnection dbConnection, IDbTransaction dbTransaction = null) | |||
{ | |||
CheckIsAdoNet(name); | |||
PrepareConnection(dbConnection, ref dbTransaction); | |||
var content = Helper.ToJson(contentObj); | |||
var content = Serialize(contentObj); | |||
PublishWithTrans(name, content, dbConnection, dbTransaction); | |||
} | |||
@@ -105,13 +73,27 @@ namespace DotNetCore.CAP.MySql | |||
PrepareConnection(dbConnection, ref dbTransaction); | |||
var content = Helper.ToJson(contentObj); | |||
var content = Serialize(contentObj); | |||
return PublishWithTransAsync(name, content, dbConnection, dbTransaction); | |||
} | |||
#region private methods | |||
private string Serialize<T>(T obj) | |||
{ | |||
string content = string.Empty; | |||
if (Helper.IsComplexType(typeof(T))) | |||
{ | |||
content = Helper.ToJson(obj); | |||
} | |||
else | |||
{ | |||
content = obj?.ToString(); | |||
} | |||
return content; | |||
} | |||
private void PrepareConnection(IDbConnection dbConnection, ref IDbTransaction dbTransaction) | |||
{ | |||
if (dbConnection == null) | |||
@@ -38,25 +38,11 @@ namespace DotNetCore.CAP.SqlServer | |||
} | |||
} | |||
public void Publish(string name, string content) | |||
{ | |||
CheckIsUsingEF(name); | |||
PublishCore(name, content); | |||
} | |||
public Task PublishAsync(string name, string content) | |||
{ | |||
CheckIsUsingEF(name); | |||
return PublishCoreAsync(name, content); | |||
} | |||
public void Publish<T>(string name, T contentObj) | |||
{ | |||
CheckIsUsingEF(name); | |||
var content = Helper.ToJson(contentObj); | |||
var content = Serialize(contentObj); | |||
PublishCore(name, content); | |||
} | |||
@@ -65,33 +51,17 @@ namespace DotNetCore.CAP.SqlServer | |||
{ | |||
CheckIsUsingEF(name); | |||
var content = Helper.ToJson(contentObj); | |||
var content = Serialize(contentObj); | |||
return PublishCoreAsync(name, content); | |||
} | |||
public void Publish(string name, string content, IDbConnection dbConnection, IDbTransaction dbTransaction = null) | |||
{ | |||
CheckIsAdoNet(name); | |||
PrepareConnection(dbConnection, ref dbTransaction); | |||
PublishWithTrans(name, content, dbConnection, dbTransaction); | |||
} | |||
public Task PublishAsync(string name, string content, IDbConnection dbConnection, IDbTransaction dbTransaction = null) | |||
{ | |||
CheckIsAdoNet(name); | |||
PrepareConnection(dbConnection, ref dbTransaction); | |||
return PublishWithTransAsync(name, content, dbConnection, dbTransaction); | |||
} | |||
public void Publish<T>(string name, T contentObj, IDbConnection dbConnection, IDbTransaction dbTransaction = null) | |||
{ | |||
CheckIsAdoNet(name); | |||
PrepareConnection(dbConnection, ref dbTransaction); | |||
var content = Helper.ToJson(contentObj); | |||
var content = Serialize(contentObj); | |||
PublishWithTrans(name, content, dbConnection, dbTransaction); | |||
} | |||
@@ -101,13 +71,27 @@ namespace DotNetCore.CAP.SqlServer | |||
CheckIsAdoNet(name); | |||
PrepareConnection(dbConnection, ref dbTransaction); | |||
var content = Helper.ToJson(contentObj); | |||
var content = Serialize(contentObj); | |||
return PublishWithTransAsync(name, content, dbConnection, dbTransaction); | |||
} | |||
#region private methods | |||
private string Serialize<T>(T obj) | |||
{ | |||
string content = string.Empty; | |||
if (Helper.IsComplexType(typeof(T))) | |||
{ | |||
content = Helper.ToJson(obj); | |||
} | |||
else | |||
{ | |||
content = obj.ToString(); | |||
} | |||
return content; | |||
} | |||
private void PrepareConnection(IDbConnection dbConnection, ref IDbTransaction dbTransaction) | |||
{ | |||
if (dbConnection == null) | |||
@@ -8,28 +8,6 @@ namespace DotNetCore.CAP | |||
/// </summary> | |||
public interface ICapPublisher | |||
{ | |||
/// <summary> | |||
/// (EntityFramework) Asynchronous publish a message. | |||
/// <para> | |||
/// If you are using the EntityFramework, you need to configure the DbContextType first. | |||
/// otherwise you need to use overloaded method with IDbConnection and IDbTransaction. | |||
/// </para> | |||
/// </summary> | |||
/// <param name="name">the topic name or exchange router key.</param> | |||
/// <param name="content">message body content.</param> | |||
Task PublishAsync(string name, string content); | |||
/// <summary> | |||
/// (EntityFramework) Publish a message. | |||
/// <para> | |||
/// If you are using the EntityFramework, you need to configure the DbContextType first. | |||
/// otherwise you need to use overloaded method with IDbConnection and IDbTransaction. | |||
/// </para> | |||
/// </summary> | |||
/// <param name="name">the topic name or exchange router key.</param> | |||
/// <param name="content">message body content.</param> | |||
void Publish(string name, string content); | |||
/// <summary> | |||
/// (EntityFramework) Asynchronous publish a object message. | |||
/// <para> | |||
@@ -54,24 +32,6 @@ namespace DotNetCore.CAP | |||
/// <param name="contentObj">message body content, that will be serialized of json.</param> | |||
void Publish<T>(string name, T contentObj); | |||
/// <summary> | |||
/// (ado.net) Asynchronous publish a message. | |||
/// </summary> | |||
/// <param name="name">the topic name or exchange router key.</param> | |||
/// <param name="content">message body content</param> | |||
/// <param name="dbConnection">the connection of <see cref="IDbConnection"/></param> | |||
/// <param name="dbTransaction">the transaction of <see cref="IDbTransaction"/></param> | |||
Task PublishAsync(string name, string content, IDbConnection dbConnection, IDbTransaction dbTransaction = null); | |||
/// <summary> | |||
/// (ado.net) Publish a message. | |||
/// </summary> | |||
/// <param name="name">the topic name or exchange router key.</param> | |||
/// <param name="content">message body content.</param> | |||
/// <param name="dbConnection">the connection of <see cref="IDbConnection"/></param> | |||
/// <param name="dbTransaction">the transaction of <see cref="IDbTransaction"/></param> | |||
void Publish(string name, string content, IDbConnection dbConnection, IDbTransaction dbTransaction = null); | |||
/// <summary> | |||
/// (ado.net) Asynchronous publish a object message. | |||
/// </summary> | |||