diff --git a/README.zh-cn.md b/README.zh-cn.md index 165cab7..6604220 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -16,32 +16,32 @@ CAP 这是CAP集在ASP.NET Core 微服务架构中的一个示意图: -![](http://images2015.cnblogs.com/blog/250417/201706/250417-20170630143600289-1065294295.png) +![](http://images2015.cnblogs.com/blog/250417/201707/250417-20170705175827128-1203291469.png) > 图中实线部分代表用户代码,虚线部分代表CAP内部实现。 ## Getting Started -### NuGet 暂未发布 +### NuGet 你可以运行以下下命令在你的项目中安装 CAP。 如果你的消息队列使用的是 Kafka 的话,你可以: ``` -PM> Install-Package DotNetCore.CAP.Kafka +PM> Install-Package DotNetCore.CAP.Kafka -Pre ``` 如果你的消息队列使用的是 RabbitMQ 的话,你可以: ``` -PM> Install-Package DotNetCore.CAP.RabbitMQ +PM> Install-Package DotNetCore.CAP.RabbitMQ -Pre ``` CAP 默认提供了 Entity Framwork 作为数据库存储: ``` -PM> Install-Package DotNetCore.CAP.EntityFrameworkCore +PM> Install-Package DotNetCore.CAP.EntityFrameworkCore -Pre ``` ### Configuration @@ -57,7 +57,7 @@ public void ConfigureServices(IServiceCollection services) services.AddCap() .AddEntityFrameworkStores() - .AddKafka(x => x.Servers = "localhost:9453"); + .AddKafka(x => x.Servers = "localhost:9092"); } public void Configure(IApplicationBuilder app) @@ -100,9 +100,7 @@ public class PublishController : Controller **Action Method** -在Action上添加 Attribute 来订阅相关消息。 - -如果你使用的是 Kafak 则使用 `[KafkaTopic()]`, 如果是 RabbitMQ 则使用 `[RabbitMQTopic()]` +在 Action 上添加 CapSubscribeAttribute 来订阅相关消息。 ```cs public class PublishController : Controller @@ -116,7 +114,7 @@ public class PublishController : Controller [NoAction] - [KafkaTopic("xxx.services.account.check")] + [CapSubscribe("xxx.services.account.check")] public async Task CheckReceivedMessage(Person person) { Console.WriteLine(person.Name); @@ -129,7 +127,7 @@ public class PublishController : Controller **Service Method** -如果你的订阅方法没有位于 Controller 中,则你订阅的类需要继承 `IConsumerService`: +如果你的订阅方法没有位于 Controller 中,则你订阅的类需要继承 `ICapSubscribe`: ```cs @@ -141,7 +139,7 @@ namespace xxx.Service } - public class SubscriberService: ISubscriberService, IConsumerService + public class SubscriberService: ISubscriberService, ICapSubscribe { [KafkaTopic("xxx.services.account.check")] public void CheckReceivedMessage(Person person) diff --git a/build/common.props b/build/common.props index 388ebcd..c82b701 100644 --- a/build/common.props +++ b/build/common.props @@ -8,12 +8,12 @@ CAP - Savorboard;dotnetcore + savorboard;dotnetcore https://github.com/dotnetcore/CAP git https://avatars2.githubusercontent.com/u/19404084 https://github.com/dotnetcore/CAP - https://github.com/dotnetcore/CAP/blob/master/LICENSE + https://github.com/dotnetcore/CAP/blob/master/LICENSE.txt aspnetcore;cap;consistency Eventually consistency in distributed architectures. diff --git a/samples/Sample.Kafka/Controllers/ValuesController.cs b/samples/Sample.Kafka/Controllers/ValuesController.cs index fe787d4..83afd71 100644 --- a/samples/Sample.Kafka/Controllers/ValuesController.cs +++ b/samples/Sample.Kafka/Controllers/ValuesController.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc; namespace Sample.Kafka.Controllers { [Route("api/[controller]")] - public class ValuesController : Controller, IConsumerService + public class ValuesController : Controller, ICapSubscribe { private readonly ICapProducerService _producer; @@ -24,7 +24,7 @@ namespace Sample.Kafka.Controllers } public string ServerPath => ((IHostingEnvironment)HttpContext.RequestServices.GetService(typeof(IHostingEnvironment))).ContentRootPath; - [KafkaTopic("zzwl.topic.finace.callBack", Group = "test")] + [CapSubscribe("zzwl.topic.finace.callBack", Group = "test")] public void KafkaTest(Person person) { Console.WriteLine(person.Name); diff --git a/src/DotNetCore.CAP.Kafka/KafkaTopicAttribute.cs b/src/DotNetCore.CAP.Kafka/CapSubscribeAttribute.cs similarity index 58% rename from src/DotNetCore.CAP.Kafka/KafkaTopicAttribute.cs rename to src/DotNetCore.CAP.Kafka/CapSubscribeAttribute.cs index 9f7b304..08d8c13 100644 --- a/src/DotNetCore.CAP.Kafka/KafkaTopicAttribute.cs +++ b/src/DotNetCore.CAP.Kafka/CapSubscribeAttribute.cs @@ -2,15 +2,21 @@ namespace DotNetCore.CAP.Kafka { - public class KafkaTopicAttribute : TopicAttribute + public class CapSubscribeAttribute : TopicAttribute { - public KafkaTopicAttribute(string topicName) + public CapSubscribeAttribute(string topicName) : this(topicName, 0) { } - public KafkaTopicAttribute(string topicName, int partition) + /// + /// Not support + /// + public CapSubscribeAttribute(string topicName, int partition) : this(topicName, partition, 0) { } - public KafkaTopicAttribute(string topicName, int partition, long offset) + /// + /// Not support + /// + public CapSubscribeAttribute(string topicName, int partition, long offset) : base(topicName) { Offset = offset; diff --git a/src/DotNetCore.CAP.RabbitMQ/CapSubscribeAttribute.cs b/src/DotNetCore.CAP.RabbitMQ/CapSubscribeAttribute.cs new file mode 100644 index 0000000..5e33a1c --- /dev/null +++ b/src/DotNetCore.CAP.RabbitMQ/CapSubscribeAttribute.cs @@ -0,0 +1,12 @@ +锘縰sing DotNetCore.CAP.Abstractions; + +namespace DotNetCore.CAP.RabbitMQ +{ + public class CapSubscribeAttribute : TopicAttribute + { + public CapSubscribeAttribute(string routingKey) : base(routingKey) + { + + } + } +} \ No newline at end of file diff --git a/src/DotNetCore.CAP.RabbitMQ/RabbitMQTopicAttribute.cs b/src/DotNetCore.CAP.RabbitMQ/RabbitMQTopicAttribute.cs deleted file mode 100644 index 1b6e027..0000000 --- a/src/DotNetCore.CAP.RabbitMQ/RabbitMQTopicAttribute.cs +++ /dev/null @@ -1,11 +0,0 @@ -锘縰sing DotNetCore.CAP.Abstractions; - -namespace DotNetCore.CAP.RabbitMQ -{ - public class RabbitMQTopicAttribute : TopicAttribute - { - public RabbitMQTopicAttribute(string routingKey) : base(routingKey) - { - } - } -} \ No newline at end of file diff --git a/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs b/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs index 49a6630..cbfe006 100644 --- a/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs +++ b/src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs @@ -67,9 +67,9 @@ namespace Microsoft.Extensions.DependencyInjection foreach (var rejectedServices in services) { if (rejectedServices.ImplementationType != null - && typeof(IConsumerService).IsAssignableFrom(rejectedServices.ImplementationType)) + && typeof(ICapSubscribe).IsAssignableFrom(rejectedServices.ImplementationType)) - consumerListenerServices.Add(typeof(IConsumerService), rejectedServices.ImplementationType); + consumerListenerServices.Add(typeof(ICapSubscribe), rejectedServices.ImplementationType); } foreach (var service in consumerListenerServices) diff --git a/src/DotNetCore.CAP/IConsumerService.cs b/src/DotNetCore.CAP/ICapSubscribe.cs similarity index 81% rename from src/DotNetCore.CAP/IConsumerService.cs rename to src/DotNetCore.CAP/ICapSubscribe.cs index 69c60ef..b358609 100644 --- a/src/DotNetCore.CAP/IConsumerService.cs +++ b/src/DotNetCore.CAP/ICapSubscribe.cs @@ -3,7 +3,7 @@ /// /// An empty interface, which is used to mark the current class have a CAP methods. /// - public interface IConsumerService + public interface ICapSubscribe { } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs index d80d205..4523a1a 100644 --- a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs +++ b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs @@ -54,11 +54,11 @@ namespace DotNetCore.CAP.Internal { var executorDescriptorList = new List(); - var consumerServices = provider.GetServices(); + var consumerServices = provider.GetServices(); foreach (var service in consumerServices) { var typeInfo = service.GetType().GetTypeInfo(); - if (!typeof(IConsumerService).GetTypeInfo().IsAssignableFrom(typeInfo)) + if (!typeof(ICapSubscribe).GetTypeInfo().IsAssignableFrom(typeInfo)) { continue; } diff --git a/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs b/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs index 5667298..2d646f0 100644 --- a/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs +++ b/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs @@ -58,7 +58,7 @@ namespace DotNetCore.CAP.Test public interface IFooTest { } public interface IBarTest { } - public class CandidatesFooTest : IFooTest, IConsumerService + public class CandidatesFooTest : IFooTest, ICapSubscribe { [CandidatesTopic("Candidates.Foo")] public Task GetFoo()