Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
ea2cf5f9
Commit
ea2cf5f9
authored
Jul 05, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor.
parent
28a0c4c2
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
42 additions
and
26 deletions
+42
-26
README.zh-cn.md
README.zh-cn.md
+10
-12
common.props
build/common.props
+2
-2
ValuesController.cs
samples/Sample.Kafka/Controllers/ValuesController.cs
+2
-2
CapSubscribeAttribute.cs
src/DotNetCore.CAP.Kafka/CapSubscribeAttribute.cs
+10
-4
CapSubscribeAttribute.cs
src/DotNetCore.CAP.RabbitMQ/CapSubscribeAttribute.cs
+12
-0
CAP.ServiceCollectionExtensions.cs
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs
+2
-2
ICapSubscribe.cs
src/DotNetCore.CAP/ICapSubscribe.cs
+1
-1
IConsumerServiceSelector.Default.cs
...tNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs
+2
-2
ConsumerServiceSelectorTest.cs
test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs
+1
-1
No files found.
README.zh-cn.md
View file @
ea2cf5f9
...
...
@@ -16,32 +16,32 @@ CAP
这是CAP集在ASP.NET Core 微服务架构中的一个示意图:


> 图中实线部分代表用户代码,虚线部分代表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
<
AppDbContext
>()
.
AddKafka
(
x
=>
x
.
Servers
=
"localhost:9
453
"
);
.
AddKafka
(
x
=>
x
.
Servers
=
"localhost:9
092
"
);
}
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 中,则你订阅的类需要继承
`IC
onsumerServic
e`
:
如果你的订阅方法没有位于 Controller 中,则你订阅的类需要继承
`IC
apSubscrib
e`
:
```
cs
...
...
@@ -141,7 +139,7 @@ namespace xxx.Service
}
public
class
SubscriberService
:
ISubscriberService
,
IC
onsumerServic
e
public
class
SubscriberService
:
ISubscriberService
,
IC
apSubscrib
e
{
[
KafkaTopic
(
"xxx.services.account.check"
)]
public
void
CheckReceivedMessage
(
Person
person
)
...
...
build/common.props
View file @
ea2cf5f9
...
...
@@ -8,12 +8,12 @@
<PropertyGroup Label="Package">
<Product>CAP</Product>
<Authors>
S
avorboard;dotnetcore</Authors>
<Authors>
s
avorboard;dotnetcore</Authors>
<RepositoryUrl>https://github.com/dotnetcore/CAP</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageIconUrl>https://avatars2.githubusercontent.com/u/19404084</PackageIconUrl>
<PackageProjectUrl>https://github.com/dotnetcore/CAP</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/dotnetcore/CAP/blob/master/LICENSE</PackageLicenseUrl>
<PackageLicenseUrl>https://github.com/dotnetcore/CAP/blob/master/LICENSE
.txt
</PackageLicenseUrl>
<PackageTags>aspnetcore;cap;consistency</PackageTags>
<Description>Eventually consistency in distributed architectures.</Description>
</PropertyGroup>
...
...
samples/Sample.Kafka/Controllers/ValuesController.cs
View file @
ea2cf5f9
...
...
@@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc;
namespace
Sample.Kafka.Controllers
{
[
Route
(
"api/[controller]"
)]
public
class
ValuesController
:
Controller
,
IC
onsumerServic
e
public
class
ValuesController
:
Controller
,
IC
apSubscrib
e
{
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
);
...
...
src/DotNetCore.CAP.Kafka/
KafkaTopic
Attribute.cs
→
src/DotNetCore.CAP.Kafka/
CapSubscribe
Attribute.cs
View file @
ea2cf5f9
...
...
@@ -2,15 +2,21 @@
namespace
DotNetCore.CAP.Kafka
{
public
class
KafkaTopic
Attribute
:
TopicAttribute
public
class
CapSubscribe
Attribute
:
TopicAttribute
{
public
KafkaTopic
Attribute
(
string
topicName
)
public
CapSubscribe
Attribute
(
string
topicName
)
:
this
(
topicName
,
0
)
{
}
public
KafkaTopicAttribute
(
string
topicName
,
int
partition
)
/// <summary>
/// Not support
/// </summary>
public
CapSubscribeAttribute
(
string
topicName
,
int
partition
)
:
this
(
topicName
,
partition
,
0
)
{
}
public
KafkaTopicAttribute
(
string
topicName
,
int
partition
,
long
offset
)
/// <summary>
/// Not support
/// </summary>
public
CapSubscribeAttribute
(
string
topicName
,
int
partition
,
long
offset
)
:
base
(
topicName
)
{
Offset
=
offset
;
...
...
src/DotNetCore.CAP.RabbitMQ/
RabbitMQTopic
Attribute.cs
→
src/DotNetCore.CAP.RabbitMQ/
CapSubscribe
Attribute.cs
View file @
ea2cf5f9
...
...
@@ -2,10 +2,11 @@
namespace
DotNetCore.CAP.RabbitMQ
{
public
class
RabbitMQTopic
Attribute
:
TopicAttribute
public
class
CapSubscribe
Attribute
:
TopicAttribute
{
public
RabbitMQTopic
Attribute
(
string
routingKey
)
:
base
(
routingKey
)
public
CapSubscribe
Attribute
(
string
routingKey
)
:
base
(
routingKey
)
{
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs
View file @
ea2cf5f9
...
...
@@ -67,9 +67,9 @@ namespace Microsoft.Extensions.DependencyInjection
foreach
(
var
rejectedServices
in
services
)
{
if
(
rejectedServices
.
ImplementationType
!=
null
&&
typeof
(
IC
onsumerServic
e
).
IsAssignableFrom
(
rejectedServices
.
ImplementationType
))
&&
typeof
(
IC
apSubscrib
e
).
IsAssignableFrom
(
rejectedServices
.
ImplementationType
))
consumerListenerServices
.
Add
(
typeof
(
IC
onsumerServic
e
),
rejectedServices
.
ImplementationType
);
consumerListenerServices
.
Add
(
typeof
(
IC
apSubscrib
e
),
rejectedServices
.
ImplementationType
);
}
foreach
(
var
service
in
consumerListenerServices
)
...
...
src/DotNetCore.CAP/IC
onsumerServic
e.cs
→
src/DotNetCore.CAP/IC
apSubscrib
e.cs
View file @
ea2cf5f9
...
...
@@ -3,7 +3,7 @@
/// <summary>
/// An empty interface, which is used to mark the current class have a CAP methods.
/// </summary>
public
interface
IC
onsumerServic
e
public
interface
IC
apSubscrib
e
{
}
}
\ No newline at end of file
src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs
View file @
ea2cf5f9
...
...
@@ -54,11 +54,11 @@ namespace DotNetCore.CAP.Internal
{
var
executorDescriptorList
=
new
List
<
ConsumerExecutorDescriptor
>();
var
consumerServices
=
provider
.
GetServices
<
IC
onsumerServic
e
>();
var
consumerServices
=
provider
.
GetServices
<
IC
apSubscrib
e
>();
foreach
(
var
service
in
consumerServices
)
{
var
typeInfo
=
service
.
GetType
().
GetTypeInfo
();
if
(!
typeof
(
IC
onsumerServic
e
).
GetTypeInfo
().
IsAssignableFrom
(
typeInfo
))
if
(!
typeof
(
IC
apSubscrib
e
).
GetTypeInfo
().
IsAssignableFrom
(
typeInfo
))
{
continue
;
}
...
...
test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs
View file @
ea2cf5f9
...
...
@@ -58,7 +58,7 @@ namespace DotNetCore.CAP.Test
public
interface
IFooTest
{
}
public
interface
IBarTest
{
}
public
class
CandidatesFooTest
:
IFooTest
,
IC
onsumerServic
e
public
class
CandidatesFooTest
:
IFooTest
,
IC
apSubscrib
e
{
[
CandidatesTopic
(
"Candidates.Foo"
)]
public
Task
GetFoo
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment