Browse Source

Merge pull request #11 from kiss96803/develop

Update README.md in develop
master
Savorboard 7 years ago
committed by GitHub
parent
commit
1528bf8e5e
1 changed files with 39 additions and 12 deletions
  1. +39
    -12
      README.md

+ 39
- 12
README.md View File

@@ -2,8 +2,7 @@
  <a href="https://github.com/dotnetcore/CAP/blob/develop/README.zh-cn.md">中文</a>
</p>

# CAP

# CAP                       
[![Travis branch](https://img.shields.io/travis/dotnetcore/CAP/develop.svg?label=travis-ci)](https://travis-ci.org/dotnetcore/CAP)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/4mpe0tbu7n126vyw?svg=true)](https://ci.appveyor.com/project/yuleyule66/cap)
[![NuGet](https://img.shields.io/nuget/v/DotNetCore.CAP.svg)](https://www.nuget.org/packages/DotNetCore.CAP/)
@@ -29,26 +28,30 @@ This is a diagram of the CAP working in the ASP.NET Core MicroService architectu

## Getting Started

### NuGet (Coming soon)
### NuGet

You can run the following command to install the CAP in your project.

```
PM> Install-Package DotNetCore.CAP -Pre
```

If your Message Queue is using Kafka, you can:

```
PM> Install-Package DotNetCore.CAP.Kafka -Pre
```

or RabbitMQ:
If your Message Queue is using RabbitMQ, you can

```
PM> Install-Package DotNetCore.CAP.RabbitMQ -Pre
```

CAP provides EntityFramework as default database store extension :
CAP provides EntityFramework as default database store extension (The MySQL version is under development)

```
PM> Install-Package DotNetCore.CAP.EntityFrameworkCore -Pre
PM> Install-Package DotNetCore.CAP.SqlServer -Pre
```

### Configuration
@@ -60,11 +63,23 @@ public void ConfigureServices(IServiceCollection services)
{
......

services.AddDbContext<AppDbContext>();
services.AddDbContext<AppDbContext>();

services.AddCap()
.AddEntityFrameworkStores<AppDbContext>()
.AddKafka(x => x.Servers = "localhost:9092");
services.AddCap(x =>
{
// If your SqlServer is using EF for data operations, you need to add the following configuration:
// Notice: You don't need to config x.UseSqlServer(""") again!
x.UseEntityFramework<AppDbContext>();
// If you are using Dapper,you need to add the config:
x.UseSqlServer("Your ConnectionStrings");

// If your Message Queue is using RabbitMQ you need to add the config:
x.UseRabbitMQ("localhost");

// If your Message Queue is using Kafka you need to add the config:
x.UseKafka("localhost");
});
}

public void Configure(IApplicationBuilder app)
@@ -94,11 +109,23 @@ public class PublishController : Controller
[Route("~/checkAccount")]
public async Task<IActionResult> PublishMessage()
{
//Specifies the message header and content to be sent
// Specifies the message header and content to be sent
await _publisher.PublishAsync("xxx.services.account.check", new Person { Name = "Foo", Age = 11 });

return Ok();
}

[Route("~/checkAccountWithTrans")]
public async Task<IActionResult> PublishMessageWithTransaction([FromServices]AppDbContext dbContext)
{
using (var trans = dbContext.Database.BeginTransaction())
{
await _publisher.PublishAsync("xxx.services.account.check", new Person { Name = "Foo", Age = 11 });

trans.Commit();
}
return Ok();
}
}

```
@@ -148,7 +175,7 @@ namespace xxx.Service

public class SubscriberService: ISubscriberService, ICapSubscribe
{
[CapSubscribe("xxx.services.account.check")]
[KafkaTopic("xxx.services.account.check")]
public void CheckReceivedMessage(Person person)
{


Loading…
Cancel
Save