Skip to content

Commit 395e278

Browse files
author
liuhll
committed
lms.sample与CAP框架整合
1 parent bda66ad commit 395e278

File tree

16 files changed

+154
-8
lines changed

16 files changed

+154
-8
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: "3.7"
2+
3+
services:
4+
lms.rabbitmq:
5+
image: rabbitmq:management
6+
restart: always
7+
environment:
8+
RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
9+
RABBITMQ_DEFAULT_USER: "rabbitmq"
10+
RABBITMQ_DEFAULT_PASS: "rabbitmq"
11+
RABBITMQ_DEFAULT_VHOST: "/"
12+
ports:
13+
- "15672:15672"
14+
- "5672:5672"
15+
networks:
16+
- lms_service_net
17+
18+
networks:
19+
lms_service_net:
20+
external:
21+
name: lms_service_net

samples/docker-compose/infrastr/docker-compose.redis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ services:
99
networks:
1010
- lms_service_net
1111
networks:
12-
lms_test_service_net:
12+
lms_service_net:
1313
external:
1414
name: lms_service_net

samples/microservices/account/Lms.Account.Application/Accounts/AccountAppService.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System;
12
using System.Threading.Tasks;
3+
using DotNetCore.CAP;
24
using Lms.Account.Application.Contracts.Accounts;
35
using Lms.Account.Application.Contracts.Accounts.Dtos;
46
using Lms.Account.Domain.Accounts;
@@ -8,20 +10,23 @@
810

911
namespace Lms.Account.Application.Accounts
1012
{
11-
public class AccountAppService : IAccountAppService
13+
public class AccountAppService : IAccountAppService, ICapSubscribe
1214
{
1315
private readonly IAccountDomainService _accountDomainService;
14-
15-
public AccountAppService(IAccountDomainService accountDomainService)
16+
private readonly ICapPublisher _capBus;
17+
public AccountAppService(IAccountDomainService accountDomainService, ICapPublisher capBus)
1618
{
1719
_accountDomainService = accountDomainService;
20+
_capBus = capBus;
1821
}
1922

2023
public async Task<GetAccountOutput> Create(CreateAccountInput input)
2124
{
25+
2226
var account = input.MapTo<Domain.Accounts.Account>();
2327
account = await _accountDomainService.Create(account);
24-
return account.MapTo<GetAccountOutput>();
28+
await _capBus.PublishAsync("account.create.time", DateTime.Now);
29+
return account.MapTo<GetAccountOutput>();
2530
}
2631

2732
public async Task<GetAccountOutput> GetAccountByName(string name)
@@ -67,5 +72,6 @@ public Task DeductBalanceCancel(DeductBalanceInput input)
6772
{
6873
return _accountDomainService.DeductBalance(input, TccMethodType.Cancel);
6974
}
75+
7076
}
7177
}

samples/microservices/account/Lms.Account.Application/Lms.Account.Application.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Silky.Lms.AutoMapper" Version="$(LmsVersion)"/>
14+
<PackageReference Include="Silky.Lms.AutoMapper" Version="$(LmsVersion)" />
1515
</ItemGroup>
1616

1717
</Project>

samples/microservices/account/Lms.Account.Domain/Lms.Account.Domain.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13+
<PackageReference Include="DotNetCore.CAP" Version="5.1.0" />
1314
<PackageReference Include="Silky.Lms.AutoMapper" Version="$(LmsVersion)" />
1415
<PackageReference Include="Silky.Lms.Caching" Version="$(LmsVersion)" />
1516
<PackageReference Include="TanvirArjel.EFCore.GenericRepository" Version="5.3.0" />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Lms.Account.EntityFrameworkCore;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Silky.Lms.Core;
5+
6+
namespace Lms.AccountHost
7+
{
8+
public class CapConfigure : IConfigureService
9+
{
10+
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
11+
{
12+
services.AddCap(x =>
13+
{
14+
x.UseEntityFramework<UserDbContext>();
15+
x.UseRabbitMQ(z =>
16+
{
17+
z.HostName = "127.0.0.1";
18+
z.UserName = "rabbitmq";
19+
z.Password = "rabbitmq";
20+
});
21+
});
22+
}
23+
24+
public int Order { get; } = 1;
25+
}
26+
}

samples/microservices/account/Lms.AccountHost/Lms.AccountHost.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="DotNetCore.CAP.MySql" Version="5.1.0" />
10+
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="5.1.0" />
911
<PackageReference Include="Silky.Lms.NormHost" Version="$(LmsVersion)" />
1012
</ItemGroup>
1113

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Lms.Order.Application.Subscribe
4+
{
5+
public interface ISubscriberService
6+
{
7+
void CheckReceivedMessage(DateTime datetime);
8+
}
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using DotNetCore.CAP;
3+
using Microsoft.Extensions.Logging;
4+
5+
namespace Lms.Order.Application.Subscribe
6+
{
7+
public class SubscriberService : ICapSubscribe, ISubscriberService
8+
{
9+
private readonly ILogger<SubscriberService> _logger;
10+
11+
public SubscriberService(ILogger<SubscriberService> logger)
12+
{
13+
_logger = logger;
14+
}
15+
16+
[CapSubscribe("account.create.time")]
17+
public void CheckReceivedMessage(DateTime datetime)
18+
{
19+
_logger.LogInformation("Create Account Time:" + datetime.ToLocalTime());
20+
}
21+
}
22+
}

samples/microservices/order/Lms.Order.Domain/Lms.Order.Domain.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<ProjectReference Include="..\Lms.Order.Domain.Shared\Lms.Order.Domain.Shared.csproj" />
1212
</ItemGroup>
1313
<ItemGroup>
14+
<PackageReference Include="DotNetCore.CAP" Version="5.1.0" />
1415
<PackageReference Include="Silky.Lms.AutoMapper" Version="$(LmsVersion)" />
1516
<PackageReference Include="Silky.Lms.Caching" Version="$(LmsVersion)" />
1617
<PackageReference Include="TanvirArjel.EFCore.GenericRepository" Version="5.3.0" />

0 commit comments

Comments
 (0)