Commit f0040458 authored by Savorboard's avatar Savorboard

Rename CapProductorService to CapPublisher.

parent ddc99e4e
......@@ -10,9 +10,9 @@ namespace Sample.Kafka.Controllers
[Route("api/[controller]")]
public class ValuesController : Controller, ICapSubscribe
{
private readonly ICapProducerService _producer;
private readonly ICapPublisher _producer;
public ValuesController(ICapProducerService producer)
public ValuesController(ICapPublisher producer)
{
_producer = producer;
}
......@@ -35,7 +35,7 @@ namespace Sample.Kafka.Controllers
[Route("~/send")]
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();
}
......
......@@ -68,13 +68,13 @@ namespace DotNetCore.CAP
}
/// <summary>
/// Add an <see cref="ICapProducerService"/>.
/// Add an <see cref="ICapPublisher"/>.
/// </summary>
/// <typeparam name="T">The type of the service.</typeparam>
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));
}
}
}
\ No newline at end of file
......@@ -56,7 +56,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.TryAddSingleton<IJob, CapJob>();
services.TryAddTransient<DefaultCronJobRegistry>();
services.TryAddScoped<ICapProducerService, DefaultProducerService>();
services.TryAddScoped<ICapPublisher, DefaultCapPublisher>();
return new CapBuilder(services);
}
......
......@@ -6,22 +6,22 @@ using Microsoft.Extensions.Logging;
namespace DotNetCore.CAP
{
/// <summary>
/// Cap <see cref="ICapProducerService"/> default implement.
/// Cap <see cref="ICapPublisher"/> default implement.
/// </summary>
public class DefaultProducerService : ICapProducerService
public class DefaultCapPublisher : ICapPublisher
{
private readonly ICapMessageStore _store;
private readonly ILogger _logger;
public DefaultProducerService(
public DefaultCapPublisher(
ICapMessageStore store,
ILogger<DefaultProducerService> logger)
ILogger<DefaultCapPublisher> logger)
{
_store = store;
_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 (content == null) throw new ArgumentNullException(nameof(content));
......@@ -29,7 +29,7 @@ namespace DotNetCore.CAP
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));
......
......@@ -3,24 +3,24 @@
namespace DotNetCore.CAP
{
/// <summary>
/// Cap producer service for store message to database.
/// A publish service for publish a message to CAP.
/// </summary>
public interface ICapProducerService
public interface ICapPublisher
{
/// <summary>
/// Send a message to cap job.
/// Publish a string message to specified topic.
/// </summary>
/// <param name="topic">the topic name or exchange router key.</param>
/// <param name="content">message body content.</param>
Task SendAsync(string topic, string content);
Task PublishAsync(string topic, string content);
/// <summary>
/// Send a message to cap job.
/// Publis a object message to specified topic.
/// </summary>
/// <typeparam name="T">The type of conetent object.</typeparam>
/// <param name="topic">the topic name or exchange router key.</param>
/// <param name="contentObj">object instance that will be serialized of json.</param>
/// <returns></returns>
Task SendAsync<T>(string topic, T contentObj);
Task PublishAsync<T>(string topic, T contentObj);
}
}
\ No newline at end of file
......@@ -41,20 +41,20 @@ namespace DotNetCore.CAP.Test
services.AddCap().AddProducerService<MyProducerService>();
var thingy = services.BuildServiceProvider()
.GetRequiredService<ICapProducerService>() as MyProducerService;
.GetRequiredService<ICapPublisher>() as MyProducerService;
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();
}
public Task SendAsync<T>(string topic, T contentObj)
public Task PublishAsync<T>(string topic, T contentObj)
{
throw new NotImplementedException();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment