From f1f88d820bfbee33c73bd17d8d5f73bfd4345075 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sun, 7 Oct 2018 10:40:17 +0800 Subject: [PATCH 1/4] Fixed SnowflakeId workerId to random id. --- .../Infrastructure/SnowflakeId.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/DotNetCore.CAP/Infrastructure/SnowflakeId.cs b/src/DotNetCore.CAP/Infrastructure/SnowflakeId.cs index 1fcc3d0..5a1dd3a 100644 --- a/src/DotNetCore.CAP/Infrastructure/SnowflakeId.cs +++ b/src/DotNetCore.CAP/Infrastructure/SnowflakeId.cs @@ -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); } } From b6311f4a7607c95f3f44d4c2f27db0736f3f05be Mon Sep 17 00:00:00 2001 From: Savorboard Date: Mon, 8 Oct 2018 22:15:08 +0800 Subject: [PATCH 2/4] Update README.md --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e03b9ab..03e98cb 100644 --- a/README.md +++ b/README.md @@ -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(); - services.AddCap(x=>{}); + services.AddCap(x=> + { + //... + }); } ``` From a2aa446412f96ec0790560bb6b9f419e14dec4f9 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sat, 20 Oct 2018 16:08:32 +0800 Subject: [PATCH 3/4] upgrade dependent nuget packages. --- src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj | 2 +- src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj | 2 +- .../DotNetCore.CAP.PostgreSql.csproj | 2 +- .../DotNetCore.CAP.MongoDB.Test.csproj | 9 ++++++--- .../DotNetCore.CAP.MySql.Test.csproj | 11 +++++++---- .../DotNetCore.CAP.PostgreSql.Test.csproj | 11 +++++++---- .../DotNetCore.CAP.SqlServer.Test.csproj | 11 +++++++---- test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj | 11 +++++++---- 8 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj b/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj index 13388ea..a84feee 100644 --- a/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj +++ b/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj index 002ebeb..ac716ba 100644 --- a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj +++ b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj b/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj index fc76e6c..fc854c0 100644 --- a/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj +++ b/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj @@ -15,7 +15,7 @@ - + diff --git a/test/DotNetCore.CAP.MongoDB.Test/DotNetCore.CAP.MongoDB.Test.csproj b/test/DotNetCore.CAP.MongoDB.Test/DotNetCore.CAP.MongoDB.Test.csproj index b04ca28..f758ee0 100644 --- a/test/DotNetCore.CAP.MongoDB.Test/DotNetCore.CAP.MongoDB.Test.csproj +++ b/test/DotNetCore.CAP.MongoDB.Test/DotNetCore.CAP.MongoDB.Test.csproj @@ -10,9 +10,12 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers + diff --git a/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj b/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj index 1b98a58..6f6d37b 100644 --- a/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj +++ b/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj @@ -12,12 +12,15 @@ - - - + + + all + runtime; build; native; contentfiles; analyzers + + - + diff --git a/test/DotNetCore.CAP.PostgreSql.Test/DotNetCore.CAP.PostgreSql.Test.csproj b/test/DotNetCore.CAP.PostgreSql.Test/DotNetCore.CAP.PostgreSql.Test.csproj index 3177749..f1bf2bd 100644 --- a/test/DotNetCore.CAP.PostgreSql.Test/DotNetCore.CAP.PostgreSql.Test.csproj +++ b/test/DotNetCore.CAP.PostgreSql.Test/DotNetCore.CAP.PostgreSql.Test.csproj @@ -7,10 +7,13 @@ - - - - + + + + + all + runtime; build; native; contentfiles; analyzers + diff --git a/test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj b/test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj index 7df0282..5bdcd2f 100644 --- a/test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj +++ b/test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj @@ -12,13 +12,16 @@ - + - - + + all + runtime; build; native; contentfiles; analyzers + + - + diff --git a/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj b/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj index bdab81c..1b046d9 100644 --- a/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj +++ b/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj @@ -6,13 +6,16 @@ - + - - + + all + runtime; build; native; contentfiles; analyzers + + - + From 86868f5faa9cb2f733863e95bac7c63e17315400 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 26 Oct 2018 14:44:22 +0800 Subject: [PATCH 4/4] Add SourceLink Support --- CAP.sln | 1 + Directory.Build.props | 39 +++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CAP.sln b/CAP.sln index e87e109..13eac1f 100644 --- a/CAP.sln +++ b/CAP.sln @@ -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 diff --git a/Directory.Build.props b/Directory.Build.props index c4ae862..a431f52 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,18 +1,29 @@ - - - - CAP - .NET Core Community;Savorboard - https://github.com/dotnetcore/CAP - git - $(MSBuildThisFileDirectory) - https://avatars2.githubusercontent.com/u/19404084 - https://github.com/dotnetcore/CAP - https://github.com/dotnetcore/CAP/blob/master/LICENSE.txt - CAP;EventBus;Distributed Transaction - EventBus and eventually consistency in distributed architectures. - + + + + CAP + .NET Core Community;Savorboard + https://github.com/dotnetcore/CAP + git + $(MSBuildThisFileDirectory) + https://avatars2.githubusercontent.com/u/19404084 + https://github.com/dotnetcore/CAP + https://github.com/dotnetcore/CAP/blob/master/LICENSE.txt + CAP;EventBus;Distributed Transaction + EventBus outbox integration and eventually consistency in microservice architectures. + + + + + true + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + + \ No newline at end of file