@@ -31,6 +31,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{10C0818D | |||
build.cake = build.cake | |||
build.ps1 = build.ps1 | |||
build.sh = build.sh | |||
Directory.Build.props = Directory.Build.props | |||
build\index.cake = build\index.cake | |||
build\util.cake = build\util.cake | |||
build\version.cake = build\version.cake | |||
@@ -1,18 +1,29 @@ | |||
<Project> | |||
<Import Project="build\version.props" /> | |||
<PropertyGroup Label="Package"> | |||
<Product>CAP</Product> | |||
<Authors>.NET Core Community;Savorboard</Authors> | |||
<RepositoryUrl>https://github.com/dotnetcore/CAP</RepositoryUrl> | |||
<RepositoryType>git</RepositoryType> | |||
<RepositoryRoot>$(MSBuildThisFileDirectory)</RepositoryRoot> | |||
<PackageIconUrl>https://avatars2.githubusercontent.com/u/19404084</PackageIconUrl> | |||
<PackageProjectUrl>https://github.com/dotnetcore/CAP</PackageProjectUrl> | |||
<PackageLicenseUrl>https://github.com/dotnetcore/CAP/blob/master/LICENSE.txt</PackageLicenseUrl> | |||
<PackageTags>CAP;EventBus;Distributed Transaction</PackageTags> | |||
<Description>EventBus and eventually consistency in distributed architectures.</Description> | |||
</PropertyGroup> | |||
<Import Project="build\version.props" /> | |||
<PropertyGroup Label="Package"> | |||
<Product>CAP</Product> | |||
<Authors>.NET Core Community;Savorboard</Authors> | |||
<RepositoryUrl>https://github.com/dotnetcore/CAP</RepositoryUrl> | |||
<RepositoryType>git</RepositoryType> | |||
<RepositoryRoot>$(MSBuildThisFileDirectory)</RepositoryRoot> | |||
<PackageIconUrl>https://avatars2.githubusercontent.com/u/19404084</PackageIconUrl> | |||
<PackageProjectUrl>https://github.com/dotnetcore/CAP</PackageProjectUrl> | |||
<PackageLicenseUrl>https://github.com/dotnetcore/CAP/blob/master/LICENSE.txt</PackageLicenseUrl> | |||
<PackageTags>CAP;EventBus;Distributed Transaction</PackageTags> | |||
<Description>EventBus outbox integration and eventually consistency in microservice architectures.</Description> | |||
</PropertyGroup> | |||
<!-- Using SourceLink --> | |||
<PropertyGroup> | |||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | |||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | |||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All"/> | |||
</ItemGroup> | |||
</Project> |
@@ -104,7 +104,7 @@ public class PublishController : Controller | |||
{ | |||
using (var transaction = connection.BeginTransaction(_capBus, autoCommit: true)) | |||
{ | |||
//your business code | |||
//your business logic code | |||
_capBus.Publish("xxx.services.show.time", DateTime.Now); | |||
} | |||
@@ -118,7 +118,7 @@ public class PublishController : Controller | |||
{ | |||
using (var trans = dbContext.Database.BeginTransaction(_capBus, autoCommit: true)) | |||
{ | |||
//your business code | |||
//your business logic code | |||
_capBus.Publish("xxx.services.show.time", DateTime.Now); | |||
} | |||
@@ -131,7 +131,7 @@ public class PublishController : Controller | |||
### Subscribe | |||
**In Action Method** | |||
**In Controller Action** | |||
Add the Attribute `[CapSubscribe()]` on Action to subscribe message: | |||
@@ -147,7 +147,7 @@ public class PublishController : Controller | |||
``` | |||
**In Service Method** | |||
**In Business Logic Service** | |||
If your subscribe method is not in the Controller,then your subscribe class need to Inheritance `ICapSubscribe`: | |||
@@ -179,7 +179,10 @@ public void ConfigureServices(IServiceCollection services) | |||
//Note: The injection of services needs before of `services.AddCap()` | |||
services.AddTransient<ISubscriberService,SubscriberService>(); | |||
services.AddCap(x=>{}); | |||
services.AddCap(x=> | |||
{ | |||
//... | |||
}); | |||
} | |||
``` | |||
@@ -13,7 +13,7 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Confluent.Kafka" Version="0.11.5" /> | |||
<PackageReference Include="Confluent.Kafka" Version="0.11.6" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
@@ -15,7 +15,7 @@ | |||
<PackageReference Include="Dapper" Version="1.50.5" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.1.0" /> | |||
<PackageReference Include="MySqlConnector" Version="0.43.0" /> | |||
<PackageReference Include="MySqlConnector" Version="0.46.1" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
@@ -15,7 +15,7 @@ | |||
<PackageReference Include="Dapper" Version="1.50.5" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.1.0" /> | |||
<PackageReference Include="Npgsql" Version="4.0.2" /> | |||
<PackageReference Include="Npgsql" Version="4.0.3" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
@@ -2,7 +2,6 @@ | |||
// An object that generates IDs. This is broken into a separate class in case we ever want to support multiple worker threads per process | |||
using System; | |||
using System.Threading; | |||
namespace DotNetCore.CAP.Infrastructure | |||
{ | |||
@@ -24,10 +23,10 @@ namespace DotNetCore.CAP.Infrastructure | |||
private static SnowflakeId _snowflakeId; | |||
private readonly object _lock = new object(); | |||
private static readonly object s_lock = new object(); | |||
private static readonly object SLock = new object(); | |||
private long _lastTimestamp = -1L; | |||
private SnowflakeId(long workerId, long datacenterId, long sequence = 0L) | |||
public SnowflakeId(long workerId, long datacenterId, long sequence = 0L) | |||
{ | |||
WorkerId = workerId; | |||
DatacenterId = datacenterId; | |||
@@ -46,11 +45,19 @@ namespace DotNetCore.CAP.Infrastructure | |||
public long Sequence { get; internal set; } | |||
public static SnowflakeId Default(long datacenterId = 0) | |||
public static SnowflakeId Default() | |||
{ | |||
lock (s_lock) | |||
lock (SLock) | |||
{ | |||
return _snowflakeId ?? (_snowflakeId = new SnowflakeId(Thread.CurrentThread.ManagedThreadId, datacenterId)); | |||
if (_snowflakeId != null) | |||
{ | |||
return _snowflakeId; | |||
} | |||
var random = new Random(); | |||
var workerId = random.Next((int)MaxWorkerId); | |||
var datacenterId = random.Next((int)MaxDatacenterId); | |||
return _snowflakeId = new SnowflakeId(workerId, datacenterId); | |||
} | |||
} | |||
@@ -10,9 +10,12 @@ | |||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" /> | |||
<PackageReference Include="FluentAssertions" Version="5.4.1" /> | |||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> | |||
<PackageReference Include="xunit" Version="2.3.1" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | |||
<PackageReference Include="xunit" Version="2.4.0" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0"> | |||
<PrivateAssets>all</PrivateAssets> | |||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | |||
</PackageReference> | |||
</ItemGroup> | |||
<ItemGroup> | |||
@@ -12,12 +12,15 @@ | |||
<ItemGroup> | |||
<PackageReference Include="Dapper" Version="1.50.5" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | |||
<PackageReference Include="xunit" Version="2.3.1" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0"> | |||
<PrivateAssets>all</PrivateAssets> | |||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | |||
</PackageReference> | |||
<PackageReference Include="xunit" Version="2.4.0" /> | |||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.0" /> | |||
<PackageReference Include="Moq" Version="4.9.0" /> | |||
<PackageReference Include="Moq" Version="4.10.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" /> | |||
@@ -7,10 +7,13 @@ | |||
<ItemGroup> | |||
<PackageReference Include="Dapper" Version="1.50.5" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> | |||
<PackageReference Include="Npgsql" Version="4.0.2" /> | |||
<PackageReference Include="xunit" Version="2.3.1" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | |||
<PackageReference Include="Npgsql" Version="4.0.3" /> | |||
<PackageReference Include="xunit" Version="2.4.0" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0"> | |||
<PrivateAssets>all</PrivateAssets> | |||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | |||
</PackageReference> | |||
</ItemGroup> | |||
<ItemGroup> | |||
@@ -12,13 +12,16 @@ | |||
<ItemGroup> | |||
<PackageReference Include="Dapper" Version="1.50.5" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | |||
<PackageReference Include="System.Data.SqlClient" Version="4.5.0" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | |||
<PackageReference Include="xunit" Version="2.3.1" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0"> | |||
<PrivateAssets>all</PrivateAssets> | |||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | |||
</PackageReference> | |||
<PackageReference Include="xunit" Version="2.4.0" /> | |||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.0" /> | |||
<PackageReference Include="Moq" Version="4.9.0" /> | |||
<PackageReference Include="Moq" Version="4.10.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" /> | |||
@@ -6,13 +6,16 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> | |||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | |||
<PackageReference Include="System.Data.Common" Version="4.3.0" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | |||
<PackageReference Include="xunit" Version="2.3.1" /> | |||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0"> | |||
<PrivateAssets>all</PrivateAssets> | |||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | |||
</PackageReference> | |||
<PackageReference Include="xunit" Version="2.4.0" /> | |||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.0" /> | |||
<PackageReference Include="Moq" Version="4.9.0" /> | |||
<PackageReference Include="Moq" Version="4.10.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" /> | |||
</ItemGroup> | |||