@@ -10,9 +10,9 @@ namespace Sample.Kafka.Controllers | |||||
[Route("api/[controller]")] | [Route("api/[controller]")] | ||||
public class ValuesController : Controller, ICapSubscribe | public class ValuesController : Controller, ICapSubscribe | ||||
{ | { | ||||
private readonly ICapProducerService _producer; | |||||
private readonly ICapPublisher _producer; | |||||
public ValuesController(ICapProducerService producer) | |||||
public ValuesController(ICapPublisher producer) | |||||
{ | { | ||||
_producer = producer; | _producer = producer; | ||||
} | } | ||||
@@ -35,7 +35,7 @@ namespace Sample.Kafka.Controllers | |||||
[Route("~/send")] | [Route("~/send")] | ||||
public async Task<IActionResult> SendTopic() | public async Task<IActionResult> SendTopic() | ||||
{ | { | ||||
await _producer.SendAsync("zzwl.topic.finace.callBack", new Person { Name = "Test", Age = 11 }); | |||||
await _producer.PublishAsync("zzwl.topic.finace.callBack", new Person { Name = "Test", Age = 11 }); | |||||
return Ok(); | return Ok(); | ||||
} | } | ||||
@@ -68,13 +68,13 @@ namespace DotNetCore.CAP | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Add an <see cref="ICapProducerService"/>. | |||||
/// Add an <see cref="ICapPublisher"/>. | |||||
/// </summary> | /// </summary> | ||||
/// <typeparam name="T">The type of the service.</typeparam> | /// <typeparam name="T">The type of the service.</typeparam> | ||||
public virtual CapBuilder AddProducerService<T>() | public virtual CapBuilder AddProducerService<T>() | ||||
where T : class, ICapProducerService | |||||
where T : class, ICapPublisher | |||||
{ | { | ||||
return AddScoped(typeof(ICapProducerService), typeof(T)); | |||||
return AddScoped(typeof(ICapPublisher), typeof(T)); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -56,7 +56,7 @@ namespace Microsoft.Extensions.DependencyInjection | |||||
services.TryAddSingleton<IJob, CapJob>(); | services.TryAddSingleton<IJob, CapJob>(); | ||||
services.TryAddTransient<DefaultCronJobRegistry>(); | services.TryAddTransient<DefaultCronJobRegistry>(); | ||||
services.TryAddScoped<ICapProducerService, DefaultProducerService>(); | |||||
services.TryAddScoped<ICapPublisher, DefaultCapPublisher>(); | |||||
return new CapBuilder(services); | return new CapBuilder(services); | ||||
} | } | ||||
@@ -6,22 +6,22 @@ using Microsoft.Extensions.Logging; | |||||
namespace DotNetCore.CAP | namespace DotNetCore.CAP | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Cap <see cref="ICapProducerService"/> default implement. | |||||
/// Cap <see cref="ICapPublisher"/> default implement. | |||||
/// </summary> | /// </summary> | ||||
public class DefaultProducerService : ICapProducerService | |||||
public class DefaultCapPublisher : ICapPublisher | |||||
{ | { | ||||
private readonly ICapMessageStore _store; | private readonly ICapMessageStore _store; | ||||
private readonly ILogger _logger; | private readonly ILogger _logger; | ||||
public DefaultProducerService( | |||||
public DefaultCapPublisher( | |||||
ICapMessageStore store, | ICapMessageStore store, | ||||
ILogger<DefaultProducerService> logger) | |||||
ILogger<DefaultCapPublisher> logger) | |||||
{ | { | ||||
_store = store; | _store = store; | ||||
_logger = logger; | _logger = logger; | ||||
} | } | ||||
public Task SendAsync(string topic, string content) | |||||
public Task PublishAsync(string topic, string content) | |||||
{ | { | ||||
if (topic == null) throw new ArgumentNullException(nameof(topic)); | if (topic == null) throw new ArgumentNullException(nameof(topic)); | ||||
if (content == null) throw new ArgumentNullException(nameof(content)); | if (content == null) throw new ArgumentNullException(nameof(content)); | ||||
@@ -29,7 +29,7 @@ namespace DotNetCore.CAP | |||||
return StoreMessage(topic, content); | return StoreMessage(topic, content); | ||||
} | } | ||||
public Task SendAsync<T>(string topic, T contentObj) | |||||
public Task PublishAsync<T>(string topic, T contentObj) | |||||
{ | { | ||||
if (topic == null) throw new ArgumentNullException(nameof(topic)); | if (topic == null) throw new ArgumentNullException(nameof(topic)); | ||||
@@ -3,24 +3,24 @@ | |||||
namespace DotNetCore.CAP | namespace DotNetCore.CAP | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Cap producer service for store message to database. | |||||
/// A publish service for publish a message to CAP. | |||||
/// </summary> | /// </summary> | ||||
public interface ICapProducerService | |||||
public interface ICapPublisher | |||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Send a message to cap job. | |||||
/// Publish a string message to specified topic. | |||||
/// </summary> | /// </summary> | ||||
/// <param name="topic">the topic name or exchange router key.</param> | /// <param name="topic">the topic name or exchange router key.</param> | ||||
/// <param name="content">message body content.</param> | /// <param name="content">message body content.</param> | ||||
Task SendAsync(string topic, string content); | |||||
Task PublishAsync(string topic, string content); | |||||
/// <summary> | /// <summary> | ||||
/// Send a message to cap job. | |||||
/// Publis a object message to specified topic. | |||||
/// </summary> | /// </summary> | ||||
/// <typeparam name="T">The type of conetent object.</typeparam> | /// <typeparam name="T">The type of conetent object.</typeparam> | ||||
/// <param name="topic">the topic name or exchange router key.</param> | /// <param name="topic">the topic name or exchange router key.</param> | ||||
/// <param name="contentObj">object instance that will be serialized of json.</param> | /// <param name="contentObj">object instance that will be serialized of json.</param> | ||||
/// <returns></returns> | /// <returns></returns> | ||||
Task SendAsync<T>(string topic, T contentObj); | |||||
Task PublishAsync<T>(string topic, T contentObj); | |||||
} | } | ||||
} | } |
@@ -41,20 +41,20 @@ namespace DotNetCore.CAP.Test | |||||
services.AddCap().AddProducerService<MyProducerService>(); | services.AddCap().AddProducerService<MyProducerService>(); | ||||
var thingy = services.BuildServiceProvider() | var thingy = services.BuildServiceProvider() | ||||
.GetRequiredService<ICapProducerService>() as MyProducerService; | |||||
.GetRequiredService<ICapPublisher>() as MyProducerService; | |||||
Assert.NotNull(thingy); | Assert.NotNull(thingy); | ||||
} | } | ||||
private class MyProducerService : ICapProducerService | |||||
private class MyProducerService : ICapPublisher | |||||
{ | { | ||||
public Task SendAsync(string topic, string content) | |||||
public Task PublishAsync(string topic, string content) | |||||
{ | { | ||||
throw new NotImplementedException(); | throw new NotImplementedException(); | ||||
} | } | ||||
public Task SendAsync<T>(string topic, T contentObj) | |||||
public Task PublishAsync<T>(string topic, T contentObj) | |||||
{ | { | ||||
throw new NotImplementedException(); | throw new NotImplementedException(); | ||||
} | } | ||||