Skip to content

Commit

Permalink
lms.sample与CAP框架整合
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhll committed Jul 7, 2021
1 parent bda66ad commit 395e278
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 8 deletions.
21 changes: 21 additions & 0 deletions samples/docker-compose/infrastr/docker-compose.rabbitmq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3.7"

services:
lms.rabbitmq:
image: rabbitmq:management
restart: always
environment:
RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
RABBITMQ_DEFAULT_USER: "rabbitmq"
RABBITMQ_DEFAULT_PASS: "rabbitmq"
RABBITMQ_DEFAULT_VHOST: "/"
ports:
- "15672:15672"
- "5672:5672"
networks:
- lms_service_net

networks:
lms_service_net:
external:
name: lms_service_net
2 changes: 1 addition & 1 deletion samples/docker-compose/infrastr/docker-compose.redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ services:
networks:
- lms_service_net
networks:
lms_test_service_net:
lms_service_net:
external:
name: lms_service_net
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Threading.Tasks;
using DotNetCore.CAP;
using Lms.Account.Application.Contracts.Accounts;
using Lms.Account.Application.Contracts.Accounts.Dtos;
using Lms.Account.Domain.Accounts;
Expand All @@ -8,20 +10,23 @@

namespace Lms.Account.Application.Accounts
{
public class AccountAppService : IAccountAppService
public class AccountAppService : IAccountAppService, ICapSubscribe
{
private readonly IAccountDomainService _accountDomainService;

public AccountAppService(IAccountDomainService accountDomainService)
private readonly ICapPublisher _capBus;
public AccountAppService(IAccountDomainService accountDomainService, ICapPublisher capBus)
{
_accountDomainService = accountDomainService;
_capBus = capBus;
}

public async Task<GetAccountOutput> Create(CreateAccountInput input)
{

var account = input.MapTo<Domain.Accounts.Account>();
account = await _accountDomainService.Create(account);
return account.MapTo<GetAccountOutput>();
await _capBus.PublishAsync("account.create.time", DateTime.Now);
return account.MapTo<GetAccountOutput>();
}

public async Task<GetAccountOutput> GetAccountByName(string name)
Expand Down Expand Up @@ -67,5 +72,6 @@ public Task DeductBalanceCancel(DeductBalanceInput input)
{
return _accountDomainService.DeductBalance(input, TccMethodType.Cancel);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Silky.Lms.AutoMapper" Version="$(LmsVersion)"/>
<PackageReference Include="Silky.Lms.AutoMapper" Version="$(LmsVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DotNetCore.CAP" Version="5.1.0" />
<PackageReference Include="Silky.Lms.AutoMapper" Version="$(LmsVersion)" />
<PackageReference Include="Silky.Lms.Caching" Version="$(LmsVersion)" />
<PackageReference Include="TanvirArjel.EFCore.GenericRepository" Version="5.3.0" />
Expand Down
26 changes: 26 additions & 0 deletions samples/microservices/account/Lms.AccountHost/CapConfigure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Lms.Account.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Silky.Lms.Core;

namespace Lms.AccountHost
{
public class CapConfigure : IConfigureService
{
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddCap(x =>
{
x.UseEntityFramework<UserDbContext>();
x.UseRabbitMQ(z =>
{
z.HostName = "127.0.0.1";
z.UserName = "rabbitmq";
z.Password = "rabbitmq";
});
});
}

public int Order { get; } = 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNetCore.CAP.MySql" Version="5.1.0" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="5.1.0" />
<PackageReference Include="Silky.Lms.NormHost" Version="$(LmsVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Lms.Order.Application.Subscribe
{
public interface ISubscriberService
{
void CheckReceivedMessage(DateTime datetime);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using DotNetCore.CAP;
using Microsoft.Extensions.Logging;

namespace Lms.Order.Application.Subscribe
{
public class SubscriberService : ICapSubscribe, ISubscriberService
{
private readonly ILogger<SubscriberService> _logger;

public SubscriberService(ILogger<SubscriberService> logger)
{
_logger = logger;
}

[CapSubscribe("account.create.time")]
public void CheckReceivedMessage(DateTime datetime)
{
_logger.LogInformation("Create Account Time:" + datetime.ToLocalTime());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ProjectReference Include="..\Lms.Order.Domain.Shared\Lms.Order.Domain.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetCore.CAP" Version="5.1.0" />
<PackageReference Include="Silky.Lms.AutoMapper" Version="$(LmsVersion)" />
<PackageReference Include="Silky.Lms.Caching" Version="$(LmsVersion)" />
<PackageReference Include="TanvirArjel.EFCore.GenericRepository" Version="5.3.0" />
Expand Down
28 changes: 28 additions & 0 deletions samples/microservices/order/Lms.OrderHost/CapConfigure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Lms.Order.Application.Subscribe;
using Lms.Order.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Silky.Lms.Core;

namespace Lms.OrderHost
{
public class CapConfigure : IConfigureService
{
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddTransient<ISubscriberService,SubscriberService>();
services.AddCap(x =>
{
x.UseEntityFramework<OrderDbContext>();
x.UseRabbitMQ(z =>
{
z.HostName = "127.0.0.1";
z.UserName = "rabbitmq";
z.Password = "rabbitmq";
});
});
}

public int Order { get; } = 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNetCore.CAP.MySql" Version="5.1.0" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="5.1.0" />
<PackageReference Include="Silky.Lms.NormHost" Version="$(LmsVersion)" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<ProjectReference Include="..\Lms.Stock.Domain.Shared\Lms.Stock.Domain.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetCore.CAP" Version="5.1.0" />
<PackageReference Include="Silky.Lms.AutoMapper" Version="$(LmsVersion)" />
<PackageReference Include="Silky.Lms.Caching" Version="$(LmsVersion)" />
<PackageReference Include="TanvirArjel.EFCore.GenericRepository" Version="5.3.0" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions samples/microservices/stock/Lms.StockHost/CapConfigure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Lms.Stock.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Silky.Lms.Core;

namespace Lms.StockHost
{
public class CapConfigure : IConfigureService
{
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddCap(x =>
{
x.UseEntityFramework<StockDbContext>();
x.UseRabbitMQ(z =>
{
z.HostName = "127.0.0.1";
z.UserName = "rabbitmq";
z.Password = "rabbitmq";
});
});
}

public int Order { get; } = 10;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<ItemGroup>
<PackageReference Include="Silky.Lms.NormHost" Version="$(LmsVersion)" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="5.1.0" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="5.1.0" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.ContainerDev.yml">
Expand Down
2 changes: 1 addition & 1 deletion samples/sample.common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<LmsVersion>1.0.1</LmsVersion>
<LmsVersion>1.0.2</LmsVersion>
</PropertyGroup>
</Project>

0 comments on commit 395e278

Please sign in to comment.