From d4569a76fcc59bcd8cb582dda71ad3c9c7e50382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= Date: Sat, 23 Dec 2017 09:30:08 +0800 Subject: [PATCH 01/57] add setting to generate xml summary document file --- src/DotNetCore.CAP/DotNetCore.CAP.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DotNetCore.CAP/DotNetCore.CAP.csproj b/src/DotNetCore.CAP/DotNetCore.CAP.csproj index 5b22347..c3f3786 100644 --- a/src/DotNetCore.CAP/DotNetCore.CAP.csproj +++ b/src/DotNetCore.CAP/DotNetCore.CAP.csproj @@ -5,6 +5,10 @@ DotNetCore.CAP $(PackageTags); + + bin\Debug\netstandard2.0\DotNetCore.CAP.xml + 1701;1702;1705;CS1591 + From cc0612246fc2fb240845de35b200e612023a2dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= Date: Sun, 24 Dec 2017 09:30:18 +0800 Subject: [PATCH 02/57] add setting to generate xml summary document file --- src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj b/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj index 6cc0872..2bc9d2f 100644 --- a/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj +++ b/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj @@ -10,7 +10,8 @@ NU1605;NU1701 - NU1701 + NU1701;CS1591 + bin\Debug\netstandard2.0\DotNetCore.CAP.Kafka.xml From ba88d9ff5e2c93d7ebe89dbea858d1dae49377e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= Date: Mon, 25 Dec 2017 09:30:26 +0800 Subject: [PATCH 03/57] add setting to generate xml summary document file --- src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj index e6bd363..cb75f46 100644 --- a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj +++ b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj @@ -8,11 +8,16 @@ $(PackageTags);MySQL + + bin\Debug\netstandard2.0\DotNetCore.CAP.MySql.xml + 1701;1702;1705;CS1591 + + - + - + From e5e5b1ab45935753e26b3517ab9fe05a608d8079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= Date: Tue, 26 Dec 2017 09:30:35 +0800 Subject: [PATCH 04/57] add setting to generate xml summary document file --- .../DotNetCore.CAP.PostgreSql.csproj | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj b/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj index 1d4b553..b366894 100644 --- a/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj +++ b/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj @@ -8,8 +8,13 @@ $(PackageTags);PostgreSQL + + bin\Debug\netstandard2.0\DotNetCore.CAP.PostgreSql.xml + 1701;1702;1705;CS1591 + + - + From 343aac1d5d77211c95d9260c9ffaa0f0de34f9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= Date: Wed, 27 Dec 2017 09:30:42 +0800 Subject: [PATCH 05/57] add setting to generate xml summary document file --- src/DotNetCore.CAP.RabbitMQ/DotNetCore.CAP.RabbitMQ.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/DotNetCore.CAP.RabbitMQ/DotNetCore.CAP.RabbitMQ.csproj b/src/DotNetCore.CAP.RabbitMQ/DotNetCore.CAP.RabbitMQ.csproj index 55a0deb..419514f 100644 --- a/src/DotNetCore.CAP.RabbitMQ/DotNetCore.CAP.RabbitMQ.csproj +++ b/src/DotNetCore.CAP.RabbitMQ/DotNetCore.CAP.RabbitMQ.csproj @@ -7,6 +7,11 @@ DotNetCore.CAP.RabbitMQ $(PackageTags);RabbitMQ + + + bin\Debug\netstandard2.0\DotNetCore.CAP.RabbitMQ.xml + 1701;1702;1705;CS1591 + From 91d058ead266b6393f3f4804ba84d15ec8861182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= Date: Thu, 28 Dec 2017 09:30:49 +0800 Subject: [PATCH 06/57] add setting to generate xml summary document file --- .../DotNetCore.CAP.SqlServer.csproj | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj b/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj index f3388f7..18ef872 100644 --- a/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj +++ b/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj @@ -8,11 +8,16 @@ $(PackageTags);SQL Server + + bin\Debug\netstandard2.0\DotNetCore.CAP.SqlServer.xml + 1701;1702;1705;CS1591 + + - + - + From 985b796e2d63163a623cbcbc6f7653a631ee3f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= Date: Fri, 22 Dec 2017 09:31:08 +0800 Subject: [PATCH 07/57] add setting to generate xml summary document file --- .../DotNetCore.CAP.MySql.Test.csproj | 6 +++--- .../DotNetCore.CAP.PostgreSql.Test.csproj | 2 +- .../DotNetCore.CAP.SqlServer.Test.csproj | 6 +++--- test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) 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 4a371c3..e7cd172 100644 --- a/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj +++ b/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj @@ -14,14 +14,14 @@ - + - + - + 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 12113ef..2c34952 100644 --- a/test/DotNetCore.CAP.PostgreSql.Test/DotNetCore.CAP.PostgreSql.Test.csproj +++ b/test/DotNetCore.CAP.PostgreSql.Test/DotNetCore.CAP.PostgreSql.Test.csproj @@ -7,7 +7,7 @@ - + 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 0a7849f..78c7cdd 100644 --- a/test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj +++ b/test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj @@ -11,14 +11,14 @@ - + - + - + diff --git a/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj b/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj index 821057e..28bf4b2 100644 --- a/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj +++ b/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj @@ -14,7 +14,7 @@ - + From 77e13a7cd01f85c65897d9bff690aaa45e1dd4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=99=93=E4=B8=9C?= Date: Thu, 28 Dec 2017 09:31:33 +0800 Subject: [PATCH 08/57] update version to 2.1.3 --- build/version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/version.props b/build/version.props index 38a9b64..4ba57d7 100644 --- a/build/version.props +++ b/build/version.props @@ -2,7 +2,7 @@ 2 1 - 2 + 3 $(VersionMajor).$(VersionMinor).$(VersionPatch) From 29f1eb9ddbdddc35a396661292f1644d38cd1e7d Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 18 Apr 2018 13:01:30 +0800 Subject: [PATCH 09/57] fixed message enqueue exception in v2.2 --- build/version.props | 2 +- .../Diagnostics/DiagnosticListenerExtensions.cs | 6 ++++++ src/DotNetCore.CAP/Diagnostics/EventData.Broker.cs | 1 - src/DotNetCore.CAP/IPublishMessageSender.Base.cs | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build/version.props b/build/version.props index d705cb4..6f4fc75 100644 --- a/build/version.props +++ b/build/version.props @@ -2,7 +2,7 @@ 2 2 - 0 + 1 $(VersionMajor).$(VersionMinor).$(VersionPatch) diff --git a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs index e833a8e..da0cc0c 100644 --- a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs +++ b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs @@ -107,6 +107,7 @@ namespace DotNetCore.CAP.Diagnostics { if (@this.IsEnabled(CapBeforePublish)) { + eventData.Headers = new TracingHeaders(); @this.Write(CapBeforePublish, eventData); } } @@ -115,6 +116,7 @@ namespace DotNetCore.CAP.Diagnostics { if (@this.IsEnabled(CapAfterPublish)) { + eventData.Headers = new TracingHeaders(); @this.Write(CapAfterPublish, eventData); } } @@ -123,6 +125,7 @@ namespace DotNetCore.CAP.Diagnostics { if (@this.IsEnabled(CapErrorPublish)) { + eventData.Headers = new TracingHeaders(); @this.Write(CapErrorPublish, eventData); } } @@ -135,6 +138,7 @@ namespace DotNetCore.CAP.Diagnostics { if (@this.IsEnabled(CapBeforeConsume)) { + eventData.Headers = new TracingHeaders(); @this.Write(CapBeforeConsume, eventData); } @@ -145,6 +149,7 @@ namespace DotNetCore.CAP.Diagnostics { if (@this.IsEnabled(CapAfterConsume)) { + eventData.Headers = new TracingHeaders(); @this.Write(CapAfterConsume, eventData); } } @@ -153,6 +158,7 @@ namespace DotNetCore.CAP.Diagnostics { if (@this.IsEnabled(CapErrorConsume)) { + eventData.Headers = new TracingHeaders(); @this.Write(CapErrorConsume, eventData); } } diff --git a/src/DotNetCore.CAP/Diagnostics/EventData.Broker.cs b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.cs index b0a6b20..2db1794 100644 --- a/src/DotNetCore.CAP/Diagnostics/EventData.Broker.cs +++ b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.cs @@ -11,7 +11,6 @@ namespace DotNetCore.CAP.Diagnostics string brokerTopicName, string brokerTopicBody) : base(operationId, operation) { - Headers = new TracingHeaders(); BrokerAddress = brokerAddress; BrokerTopicName = brokerTopicName; BrokerTopicBody = brokerTopicBody; diff --git a/src/DotNetCore.CAP/IPublishMessageSender.Base.cs b/src/DotNetCore.CAP/IPublishMessageSender.Base.cs index eb37cfc..cc82be6 100644 --- a/src/DotNetCore.CAP/IPublishMessageSender.Base.cs +++ b/src/DotNetCore.CAP/IPublishMessageSender.Base.cs @@ -147,7 +147,7 @@ namespace DotNetCore.CAP s_diagnosticListener.WritePublishBefore(eventData); - return (operationId, eventData.Headers); + return (operationId, eventData.Headers); //if not enabled diagnostics ,the header will be null } private void TracingAfter(Guid operationId, string topic, string values, DateTimeOffset startTime, TimeSpan du) From e53863a659c135ea0547920bc3640b6e2649bdbd Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 18 Apr 2018 17:50:32 +0800 Subject: [PATCH 10/57] add log to samples --- samples/Sample.Kafka.MySql/Program.cs | 7 ++++- .../Sample.Kafka.MySql.csproj | 6 +++++ samples/Sample.Kafka.MySql/Startup.cs | 3 +-- samples/Sample.Kafka.MySql/nlog.config | 26 +++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 samples/Sample.Kafka.MySql/nlog.config diff --git a/samples/Sample.Kafka.MySql/Program.cs b/samples/Sample.Kafka.MySql/Program.cs index 7d62e55..976b20a 100644 --- a/samples/Sample.Kafka.MySql/Program.cs +++ b/samples/Sample.Kafka.MySql/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; +using NLog.Web; namespace Sample.Kafka.MySql { @@ -14,7 +15,11 @@ namespace Sample.Kafka.MySql public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() + .ConfigureLogging((hostingContext, builder) => + { + hostingContext.HostingEnvironment.ConfigureNLog("nlog.config"); + }) + .UseNLog() .Build(); - } } \ No newline at end of file diff --git a/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj b/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj index ad812ae..88c0c1d 100644 --- a/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj +++ b/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj @@ -10,6 +10,7 @@ + @@ -20,5 +21,10 @@ + + + PreserveNewest + + diff --git a/samples/Sample.Kafka.MySql/Startup.cs b/samples/Sample.Kafka.MySql/Startup.cs index 419e48e..12040d7 100644 --- a/samples/Sample.Kafka.MySql/Startup.cs +++ b/samples/Sample.Kafka.MySql/Startup.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; namespace Sample.Kafka.MySql diff --git a/samples/Sample.Kafka.MySql/nlog.config b/samples/Sample.Kafka.MySql/nlog.config new file mode 100644 index 0000000..5bfcf49 --- /dev/null +++ b/samples/Sample.Kafka.MySql/nlog.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From b12e376ded2d92f3c807d9873fb9b844303cb29b Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 18 Apr 2018 17:51:45 +0800 Subject: [PATCH 11/57] Improved log output. #114 --- .../IPublishMessageSender.Base.cs | 33 ++++++++----------- .../Internal/PublisherSentFailedException.cs | 4 +++ src/DotNetCore.CAP/LoggerExtensions.cs | 22 ++++++------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/DotNetCore.CAP/IPublishMessageSender.Base.cs b/src/DotNetCore.CAP/IPublishMessageSender.Base.cs index cc82be6..a597169 100644 --- a/src/DotNetCore.CAP/IPublishMessageSender.Base.cs +++ b/src/DotNetCore.CAP/IPublishMessageSender.Base.cs @@ -67,15 +67,13 @@ namespace DotNetCore.CAP } else { - TracingError(operationId, message.Name, sendValues, result.Exception, startTime, stopwatch.Elapsed); - - _logger.MessagePublishException(message.Id, result.Exception); + TracingError(operationId, message, result, startTime, stopwatch.Elapsed); await SetFailedState(message, result.Exception, out bool stillRetry); if (stillRetry) { - _logger.SenderRetrying(3); + _logger.SenderRetrying(message.Id, message.Retries); await SendAsync(message); } @@ -109,20 +107,11 @@ namespace DotNetCore.CAP private Task SetFailedState(CapPublishedMessage message, Exception ex, out bool stillRetry) { IState newState = new FailedState(); - - if (ex is PublisherSentFailedException) - { - stillRetry = false; - message.Retries = _options.FailedRetryCount; // not retry if PublisherSentFailedException - } - else + stillRetry = UpdateMessageForRetryAsync(message); + if (stillRetry) { - stillRetry = UpdateMessageForRetryAsync(message); - if (stillRetry) - { - _logger.ConsumerExecutionFailedWillRetry(ex); - return Task.CompletedTask; - } + _logger.ConsumerExecutionFailedWillRetry(ex); + return Task.CompletedTask; } AddErrorReasonToContent(message, ex); @@ -166,14 +155,18 @@ namespace DotNetCore.CAP _logger.MessageHasBeenSent(du.TotalSeconds); } - private void TracingError(Guid operationId, string topic, string values, Exception ex, DateTimeOffset startTime, TimeSpan du) + private void TracingError(Guid operationId, CapPublishedMessage message, OperateResult result, DateTimeOffset startTime, TimeSpan du) { + var ex = new PublisherSentFailedException(result.ToString(), result.Exception); + + _logger.MessagePublishException(message.Id, result.ToString(), ex); + var eventData = new BrokerPublishErrorEventData( operationId, "", ServersAddress, - topic, - values, + message.Name, + message.Content, ex, startTime, du); diff --git a/src/DotNetCore.CAP/Internal/PublisherSentFailedException.cs b/src/DotNetCore.CAP/Internal/PublisherSentFailedException.cs index b0f0a2c..9be1758 100644 --- a/src/DotNetCore.CAP/Internal/PublisherSentFailedException.cs +++ b/src/DotNetCore.CAP/Internal/PublisherSentFailedException.cs @@ -7,6 +7,10 @@ namespace DotNetCore.CAP.Internal { public class PublisherSentFailedException : Exception { + public PublisherSentFailedException(string message) : base(message) + { + } + public PublisherSentFailedException(string message, Exception ex) : base(message, ex) { } diff --git a/src/DotNetCore.CAP/LoggerExtensions.cs b/src/DotNetCore.CAP/LoggerExtensions.cs index 031be9d..a0096e6 100644 --- a/src/DotNetCore.CAP/LoggerExtensions.cs +++ b/src/DotNetCore.CAP/LoggerExtensions.cs @@ -17,10 +17,10 @@ namespace DotNetCore.CAP private static readonly Action _modelBinderFormattingException; private static readonly Action _consumerFailedWillRetry; private static readonly Action _consumerExecuted; - private static readonly Action _senderRetrying; + private static readonly Action _senderRetrying; private static readonly Action _exceptionOccuredWhileExecuting; private static readonly Action _messageHasBeenSent; - private static readonly Action _messagePublishException; + private static readonly Action _messagePublishException; static LoggerExtensions() { @@ -60,10 +60,10 @@ namespace DotNetCore.CAP "When call subscribe method, a parameter format conversion exception occurs. MethodName:'{MethodName}' ParameterName:'{ParameterName}' Content:'{Content}'." ); - _senderRetrying = LoggerMessage.Define( + _senderRetrying = LoggerMessage.Define( LogLevel.Debug, 3, - "Retrying send a message: {Retries}..."); + "The {Retries}th retrying send a message failed. message id: {MessageId} "); _consumerExecuted = LoggerMessage.Define( LogLevel.Debug, @@ -78,17 +78,17 @@ namespace DotNetCore.CAP _exceptionOccuredWhileExecuting = LoggerMessage.Define( LogLevel.Error, 6, - "An exception occured while trying to store a message: '{MessageId}'. "); + "An exception occured while trying to store a message. message id: {MessageId}"); _messageHasBeenSent = LoggerMessage.Define( LogLevel.Debug, 4, "Message published. Took: {Seconds} secs."); - _messagePublishException = LoggerMessage.Define( + _messagePublishException = LoggerMessage.Define( LogLevel.Error, 6, - "An exception occured while publishing a message: '{MessageId}'. "); + "An exception occured while publishing a message, reason:{Reason}. message id:{MessageId}"); } public static void ConsumerExecutionFailedWillRetry(this ILogger logger, Exception ex) @@ -96,9 +96,9 @@ namespace DotNetCore.CAP _consumerFailedWillRetry(logger, ex); } - public static void SenderRetrying(this ILogger logger, int retries) + public static void SenderRetrying(this ILogger logger, int messageId, int retries) { - _senderRetrying(logger, retries, null); + _senderRetrying(logger, messageId, retries, null); } public static void MessageHasBeenSent(this ILogger logger, double seconds) @@ -106,9 +106,9 @@ namespace DotNetCore.CAP _messageHasBeenSent(logger, seconds, null); } - public static void MessagePublishException(this ILogger logger, int messageId, Exception ex) + public static void MessagePublishException(this ILogger logger, int messageId, string reason, Exception ex) { - _messagePublishException(logger, messageId, ex); + _messagePublishException(logger, messageId, reason, ex); } public static void ConsumerExecuted(this ILogger logger, double seconds) From f539fd1a26c1e1cda3ca81dbce57586f27a824a5 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 18 Apr 2018 17:52:28 +0800 Subject: [PATCH 12/57] add default timeout configuration for kafka client. --- src/DotNetCore.CAP.Kafka/CAP.KafkaOptions.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DotNetCore.CAP.Kafka/CAP.KafkaOptions.cs b/src/DotNetCore.CAP.Kafka/CAP.KafkaOptions.cs index 629963b..0e4161b 100644 --- a/src/DotNetCore.CAP.Kafka/CAP.KafkaOptions.cs +++ b/src/DotNetCore.CAP.Kafka/CAP.KafkaOptions.cs @@ -57,6 +57,8 @@ namespace DotNetCore.CAP MainConfig["socket.blocking.max.ms"] = "10"; MainConfig["enable.auto.commit"] = "false"; MainConfig["log.connection.close"] = "false"; + MainConfig["request.timeout.ms"] = "3000"; + MainConfig["message.timeout.ms"] = "5000"; _kafkaConfig = MainConfig.AsEnumerable(); } From 69fdcf87c233c53947b173ec2232a0116cb891df Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 18 Apr 2018 17:53:10 +0800 Subject: [PATCH 13/57] fixed retry processor bugs. --- .../Processor/IProcessor.NeedRetry.cs | 57 ++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs b/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs index b1109a3..dbd2212 100644 --- a/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs +++ b/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs @@ -80,18 +80,29 @@ namespace DotNetCore.CAP.Processor using (var transaction = connection.CreateTransaction()) { - try + var result = await _publishExecutor.PublishAsync(message.Name, message.Content); + if (result.Succeeded) { - await _publishExecutor.PublishAsync(message.Name, message.Content); - _stateChanger.ChangeState(message, new SucceededState(), transaction); + _logger.LogInformation("The message was sent successfully during the retry. MessageId:" + message.Id); } - catch (Exception e) + else { - message.Content = Helper.AddExceptionProperty(message.Content, e); + message.Content = Helper.AddExceptionProperty(message.Content, result.Exception); + message.Retries++; + if (message.StatusName == StatusName.Scheduled) + { + message.ExpiresAt = GetDueTime(message.Added, message.Retries); + message.StatusName = StatusName.Failed; + } transaction.UpdateMessage(message); - } + if (message.Retries >= _options.FailedRetryCount) + { + _logger.LogError($"The message still sent failed after {_options.FailedRetryCount} retries. We will stop retrying the message. " + + "MessageId:" + message.Id); + } + } await transaction.CommitAsync(); } @@ -126,12 +137,44 @@ namespace DotNetCore.CAP.Processor } } - await _subscriberExecutor.ExecuteAsync(message); + using (var transaction = connection.CreateTransaction()) + { + var result = await _subscriberExecutor.ExecuteAsync(message); + if (result.Succeeded) + { + _stateChanger.ChangeState(message, new SucceededState(), transaction); + _logger.LogInformation("The message was execute successfully during the retry. MessageId:" + message.Id); + } + else + { + message.Content = Helper.AddExceptionProperty(message.Content, result.Exception); + message.Retries++; + if (message.StatusName == StatusName.Scheduled) + { + message.ExpiresAt = GetDueTime(message.Added, message.Retries); + message.StatusName = StatusName.Failed; + } + transaction.UpdateMessage(message); + + if (message.Retries >= _options.FailedRetryCount) + { + _logger.LogError($"[Subscriber]The message still executed failed after {_options.FailedRetryCount} retries. " + + "We will stop retrying to execute the message. message id:" + message.Id); + } + } + await transaction.CommitAsync(); + } context.ThrowIfStopping(); await context.WaitAsync(_delay); } } + + public DateTime GetDueTime(DateTime addedTime, int retries) + { + var retryBehavior = RetryBehavior.DefaultRetry; + return addedTime.AddSeconds(retryBehavior.RetryIn(retries)); + } } } \ No newline at end of file From d86c1e3a67461d99d6fc6c5f0c54345dda5b748b Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 18 Apr 2018 17:55:04 +0800 Subject: [PATCH 14/57] Fixed kafka producer exception log without logging when publish message. --- src/DotNetCore.CAP.Kafka/IPublishMessageSender.Kafka.cs | 8 ++------ src/DotNetCore.CAP/Infrastructure/Helper.cs | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/DotNetCore.CAP.Kafka/IPublishMessageSender.Kafka.cs b/src/DotNetCore.CAP.Kafka/IPublishMessageSender.Kafka.cs index f3e4e5d..4527eda 100644 --- a/src/DotNetCore.CAP.Kafka/IPublishMessageSender.Kafka.cs +++ b/src/DotNetCore.CAP.Kafka/IPublishMessageSender.Kafka.cs @@ -36,11 +36,7 @@ namespace DotNetCore.CAP.Kafka if (message.Error.HasError) { - return OperateResult.Failed(new OperateError - { - Code = message.Error.Code.ToString(), - Description = message.Error.Reason - }); + throw new PublisherSentFailedException(message.Error.ToString()); } _logger.LogDebug($"kafka topic message [{keyName}] has been published."); @@ -61,6 +57,6 @@ namespace DotNetCore.CAP.Kafka producer.Dispose(); } } - } + } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/Infrastructure/Helper.cs b/src/DotNetCore.CAP/Infrastructure/Helper.cs index 83d128f..3f023b9 100644 --- a/src/DotNetCore.CAP/Infrastructure/Helper.cs +++ b/src/DotNetCore.CAP/Infrastructure/Helper.cs @@ -86,7 +86,6 @@ namespace DotNetCore.CAP.Infrastructure return !CanConvertFromString(type); } - public static string AddExceptionProperty(string json, Exception exception) { var jObject = ToJObject(exception); From 28aaec7dd8e8d60fc8438822e4bea01267165a5d Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 18 Apr 2018 17:55:39 +0800 Subject: [PATCH 15/57] update version num to 2.2.2 --- build/version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/version.props b/build/version.props index 6f4fc75..ae5b04f 100644 --- a/build/version.props +++ b/build/version.props @@ -2,7 +2,7 @@ 2 2 - 1 + 2 $(VersionMajor).$(VersionMinor).$(VersionPatch) From f66713c6c4d67fac0815a5ea51a600cc9d324a00 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 20 Apr 2018 17:01:50 +0800 Subject: [PATCH 16/57] rename configuration options FailedCallback to FailedThresholdCallback --- src/DotNetCore.CAP/CAP.Options.cs | 4 +- .../Processor/IProcessor.NeedRetry.cs | 57 ++++++++++--------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/DotNetCore.CAP/CAP.Options.cs b/src/DotNetCore.CAP/CAP.Options.cs index 267a61f..05c0294 100644 --- a/src/DotNetCore.CAP/CAP.Options.cs +++ b/src/DotNetCore.CAP/CAP.Options.cs @@ -58,9 +58,9 @@ namespace DotNetCore.CAP public int FailedRetryInterval { get; set; } /// - /// We’ll invoke this call-back with message type,name,content when requeue failed message. + /// We’ll invoke this call-back with message type,name,content when retry failed (send or executed) messages equals times. /// - public Action FailedCallback { get; set; } + public Action FailedThresholdCallback { get; set; } /// /// The number of message retries, the retry will stop when the threshold is reached. diff --git a/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs b/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs index dbd2212..2f7b829 100644 --- a/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs +++ b/src/DotNetCore.CAP/Processor/IProcessor.NeedRetry.cs @@ -65,19 +65,6 @@ namespace DotNetCore.CAP.Processor continue; } - if (!hasException) - { - try - { - _options.FailedCallback?.Invoke(MessageType.Publish, message.Name, message.Content); - } - catch (Exception ex) - { - hasException = true; - _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message); - } - } - using (var transaction = connection.CreateTransaction()) { var result = await _publishExecutor.PublishAsync(message.Name, message.Content); @@ -101,6 +88,21 @@ namespace DotNetCore.CAP.Processor { _logger.LogError($"The message still sent failed after {_options.FailedRetryCount} retries. We will stop retrying the message. " + "MessageId:" + message.Id); + if (message.Retries == _options.FailedRetryCount) + { + if (!hasException) + { + try + { + _options.FailedThresholdCallback?.Invoke(MessageType.Publish, message.Name, message.Content); + } + catch (Exception ex) + { + hasException = true; + _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message); + } + } + } } } await transaction.CommitAsync(); @@ -124,19 +126,6 @@ namespace DotNetCore.CAP.Processor continue; } - if (!hasException) - { - try - { - _options.FailedCallback?.Invoke(MessageType.Subscribe, message.Name, message.Content); - } - catch (Exception ex) - { - hasException = true; - _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message); - } - } - using (var transaction = connection.CreateTransaction()) { var result = await _subscriberExecutor.ExecuteAsync(message); @@ -160,6 +149,22 @@ namespace DotNetCore.CAP.Processor { _logger.LogError($"[Subscriber]The message still executed failed after {_options.FailedRetryCount} retries. " + "We will stop retrying to execute the message. message id:" + message.Id); + + if (message.Retries == _options.FailedRetryCount) + { + if (!hasException) + { + try + { + _options.FailedThresholdCallback?.Invoke(MessageType.Subscribe, message.Name, message.Content); + } + catch (Exception ex) + { + hasException = true; + _logger.LogWarning("Failed call-back method raised an exception:" + ex.Message); + } + } + } } } await transaction.CommitAsync(); From d7c4ce534312384304cefe675ec88f8873f5d26b Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 25 Apr 2018 20:50:18 +0800 Subject: [PATCH 17/57] rename files name. --- .../{ConnectionPool.cs => IConnectionPool.Default.cs} | 0 ...ConnectionChannelPool.cs => IConnectionChannelPool.Default.cs} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/DotNetCore.CAP.Kafka/{ConnectionPool.cs => IConnectionPool.Default.cs} (100%) rename src/DotNetCore.CAP.RabbitMQ/{ConnectionChannelPool.cs => IConnectionChannelPool.Default.cs} (100%) diff --git a/src/DotNetCore.CAP.Kafka/ConnectionPool.cs b/src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs similarity index 100% rename from src/DotNetCore.CAP.Kafka/ConnectionPool.cs rename to src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs diff --git a/src/DotNetCore.CAP.RabbitMQ/ConnectionChannelPool.cs b/src/DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs similarity index 100% rename from src/DotNetCore.CAP.RabbitMQ/ConnectionChannelPool.cs rename to src/DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs From c24cc70d7d7aa7e5565bc0e5e883e5e7dc6c69de Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 25 Apr 2018 20:50:36 +0800 Subject: [PATCH 18/57] remove unused files. --- src/DotNetCore.CAP/IFetchedMessage.cs | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/DotNetCore.CAP/IFetchedMessage.cs diff --git a/src/DotNetCore.CAP/IFetchedMessage.cs b/src/DotNetCore.CAP/IFetchedMessage.cs deleted file mode 100644 index 34a78ca..0000000 --- a/src/DotNetCore.CAP/IFetchedMessage.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) .NET Core Community. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System; -using DotNetCore.CAP.Models; - -namespace DotNetCore.CAP -{ - public interface IFetchedMessage : IDisposable - { - int MessageId { get; } - - MessageType MessageType { get; } - - void RemoveFromQueue(); - - void Requeue(); - } -} \ No newline at end of file From aab167ea3b9e73bf80c45b1494670ad1f920df61 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 25 Apr 2018 20:51:05 +0800 Subject: [PATCH 19/57] modify the error comments. --- src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs | 2 +- src/DotNetCore.CAP/ICapPublisher.cs | 4 ++-- src/DotNetCore.CAP/ICapSubscribe.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs b/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs index 26760b2..4d7a321 100644 --- a/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs +++ b/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs @@ -132,7 +132,7 @@ namespace DotNetCore.CAP.Abstractions { throw new InvalidOperationException( "If you are using the EntityFramework, you need to configure the DbContextType first." + - " otherwise you need to use overloaded method with IDbConnection and IDbTransaction."); + " otherwise you need to use overloaded method with IDbTransaction."); } } diff --git a/src/DotNetCore.CAP/ICapPublisher.cs b/src/DotNetCore.CAP/ICapPublisher.cs index 8ba45e1..0688c02 100644 --- a/src/DotNetCore.CAP/ICapPublisher.cs +++ b/src/DotNetCore.CAP/ICapPublisher.cs @@ -15,7 +15,7 @@ namespace DotNetCore.CAP /// (EntityFramework) Asynchronous publish a object message. /// /// If you are using the EntityFramework, you need to configure the DbContextType first. - /// otherwise you need to use overloaded method with IDbConnection and IDbTransaction. + /// otherwise you need to use overloaded method with IDbTransaction. /// /// /// The type of content object. @@ -28,7 +28,7 @@ namespace DotNetCore.CAP /// (EntityFramework) Publish a object message. /// /// If you are using the EntityFramework, you need to configure the DbContextType first. - /// otherwise you need to use overloaded method with IDbConnection and IDbTransaction. + /// otherwise you need to use overloaded method with IDbTransaction. /// /// /// The type of content object. diff --git a/src/DotNetCore.CAP/ICapSubscribe.cs b/src/DotNetCore.CAP/ICapSubscribe.cs index 9b536ad..e223b84 100644 --- a/src/DotNetCore.CAP/ICapSubscribe.cs +++ b/src/DotNetCore.CAP/ICapSubscribe.cs @@ -4,7 +4,7 @@ namespace DotNetCore.CAP { /// - /// An empty interface, which is used to mark the current class have a CAP methods. + /// An empty interface, which is used to mark the current class have a CAP subscriber methods. /// public interface ICapSubscribe { From 01aeb132e7a2acdf2b74434fad39540d3ee1d96f Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sat, 28 Apr 2018 15:54:45 +0800 Subject: [PATCH 20/57] update samples. --- .../Controllers/ValuesController.cs | 2 +- samples/Sample.Kafka.MySql/Startup.cs | 3 ++- samples/Sample.Kafka.MySql/nlog.config | 2 +- samples/Sample.RabbitMQ.MySql/AppDbContext.cs | 9 ++----- .../Controllers/ValuesController.cs | 4 +-- samples/Sample.RabbitMQ.MySql/Program.cs | 15 +++++------ .../Sample.RabbitMQ.MySql.csproj | 6 +++++ samples/Sample.RabbitMQ.MySql/nlog.config | 26 +++++++++++++++++++ 8 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 samples/Sample.RabbitMQ.MySql/nlog.config diff --git a/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs b/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs index afcec67..6f04946 100644 --- a/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs +++ b/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs @@ -37,7 +37,7 @@ namespace Sample.Kafka.MySql.Controllers [CapSubscribe("xxx.xxx.test2")] public void Test2(int value) { - Console.WriteLine(value); + Console.WriteLine("Subscriber output message: " + value); } } } \ No newline at end of file diff --git a/samples/Sample.Kafka.MySql/Startup.cs b/samples/Sample.Kafka.MySql/Startup.cs index 12040d7..419e48e 100644 --- a/samples/Sample.Kafka.MySql/Startup.cs +++ b/samples/Sample.Kafka.MySql/Startup.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Builder; +using System; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; namespace Sample.Kafka.MySql diff --git a/samples/Sample.Kafka.MySql/nlog.config b/samples/Sample.Kafka.MySql/nlog.config index 5bfcf49..5b91105 100644 --- a/samples/Sample.Kafka.MySql/nlog.config +++ b/samples/Sample.Kafka.MySql/nlog.config @@ -7,7 +7,7 @@ internalLogFile="logs/internal-nlog.txt"> + value="---------------------------------------------------------------------------${newline}Date:${longdate} Level:${uppercase:${level}} User:${aspnet-user-identity}(${aspnet-request-ip}) Logger:${logger} URL:${aspnet-request-method} ${aspnet-request-url:IncludePort=true:IncludeQueryString=true} Action:${aspnet-mvc-action} ${newline}Message:${message} ${newline}${onexception:Exception:${exception:format=toString}}" /> diff --git a/samples/Sample.RabbitMQ.MySql/AppDbContext.cs b/samples/Sample.RabbitMQ.MySql/AppDbContext.cs index f803e26..ec83423 100644 --- a/samples/Sample.RabbitMQ.MySql/AppDbContext.cs +++ b/samples/Sample.RabbitMQ.MySql/AppDbContext.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; namespace Sample.RabbitMQ.MySql { @@ -10,8 +6,7 @@ namespace Sample.RabbitMQ.MySql { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseMySql("Server=localhost;Database=Sample.RabbitMQ.MySql;UserId=root;Password=123123;Allow User Variables=True"); - //optionsBuilder.UseMySql("Server=192.168.2.206;Database=Sample.RabbitMQ.MySql;UserId=root;Password=123123;"); + optionsBuilder.UseMySql("Server=192.168.10.110;Database=testcap;UserId=root;Password=123123;"); } } } diff --git a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs index 7b30772..1b47e5e 100644 --- a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs +++ b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs @@ -21,7 +21,7 @@ namespace Sample.RabbitMQ.MySql.Controllers public IActionResult PublishMessage() { _capBus.Publish("sample.rabbitmq.mysql", DateTime.Now); - + return Ok(); } @@ -50,7 +50,7 @@ namespace Sample.RabbitMQ.MySql.Controllers [CapSubscribe("sample.rabbitmq.mysql")] public void ReceiveMessage(DateTime time) { - Console.WriteLine("[sample.rabbitmq.mysql] message received: "+ DateTime.Now.ToString() +" , sent time: " + time.ToString()); + Console.WriteLine("[sample.rabbitmq.mysql] message received: " + DateTime.Now + ",sent time: " + time); } } } diff --git a/samples/Sample.RabbitMQ.MySql/Program.cs b/samples/Sample.RabbitMQ.MySql/Program.cs index 94095e2..3cbbe15 100644 --- a/samples/Sample.RabbitMQ.MySql/Program.cs +++ b/samples/Sample.RabbitMQ.MySql/Program.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; +using NLog.Web; namespace Sample.RabbitMQ.MySql { @@ -20,6 +14,11 @@ namespace Sample.RabbitMQ.MySql public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() + .ConfigureLogging((hostingContext, builder) => + { + hostingContext.HostingEnvironment.ConfigureNLog("nlog.config"); + }) + .UseNLog() .Build(); } } diff --git a/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj b/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj index d3a3987..5c981a3 100644 --- a/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj +++ b/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj @@ -12,6 +12,7 @@ + @@ -21,5 +22,10 @@ + + + PreserveNewest + + diff --git a/samples/Sample.RabbitMQ.MySql/nlog.config b/samples/Sample.RabbitMQ.MySql/nlog.config new file mode 100644 index 0000000..bba5bea --- /dev/null +++ b/samples/Sample.RabbitMQ.MySql/nlog.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From d99ec600828894b6af1c6de009ab9955d1781e8e Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sat, 28 Apr 2018 15:55:47 +0800 Subject: [PATCH 21/57] add logs. --- src/DotNetCore.CAP/IConsumerHandler.Default.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DotNetCore.CAP/IConsumerHandler.Default.cs b/src/DotNetCore.CAP/IConsumerHandler.Default.cs index 8d48a37..1d441ff 100644 --- a/src/DotNetCore.CAP/IConsumerHandler.Default.cs +++ b/src/DotNetCore.CAP/IConsumerHandler.Default.cs @@ -178,6 +178,8 @@ namespace DotNetCore.CAP private (Guid, string) TracingBefore(string topic, string values) { + _logger.LogDebug("CAP received topic message:" + topic); + Guid operationId = Guid.NewGuid(); var eventData = new BrokerConsumeEventData( From 4216c40a3eb9813c25744c1ff6be5867992fc6b4 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sun, 29 Apr 2018 20:07:38 +0800 Subject: [PATCH 22/57] Add unit tests for Diagnostics. --- test/DotNetCore.CAP.Test/DiagnosticsTest.cs | 241 ++++++++++++++++++ .../FakeDiagnosticListenerObserver.cs | 71 ++++++ 2 files changed, 312 insertions(+) create mode 100644 test/DotNetCore.CAP.Test/DiagnosticsTest.cs create mode 100644 test/DotNetCore.CAP.Test/FakeDiagnosticListenerObserver.cs diff --git a/test/DotNetCore.CAP.Test/DiagnosticsTest.cs b/test/DotNetCore.CAP.Test/DiagnosticsTest.cs new file mode 100644 index 0000000..b3473a9 --- /dev/null +++ b/test/DotNetCore.CAP.Test/DiagnosticsTest.cs @@ -0,0 +1,241 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; +using System.Runtime.CompilerServices; +using DotNetCore.CAP.Diagnostics; +using DotNetCore.CAP.Internal; +using Xunit; + +namespace DotNetCore.CAP.Test +{ + + public class DiagnosticsTest + { + private static readonly DiagnosticListener s_diagnosticListener = + new DiagnosticListener(CapDiagnosticListenerExtensions.DiagnosticListenerName); + + [Fact] + public void WritePublishBeforeTest() + { + Guid operationId = Guid.NewGuid(); + + DiagnosticsWapper(() => + { + var eventData = new BrokerPublishEventData(operationId, "", "", "", "", DateTimeOffset.UtcNow); + s_diagnosticListener.WritePublishBefore(eventData); + + }, kvp => + { + if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapBeforePublish)) + { + Assert.NotNull(kvp.Value); + Assert.IsType(kvp.Value); + Assert.Equal(operationId, ((BrokerPublishEventData)kvp.Value).OperationId); + } + }); + } + + [Fact] + public void WritePublishAfterTest() + { + Guid operationId = Guid.NewGuid(); + + DiagnosticsWapper(() => + { + var eventData = new BrokerPublishEndEventData(operationId, "", "", "", "", DateTimeOffset.UtcNow, TimeSpan.FromMinutes(1)); + s_diagnosticListener.WritePublishAfter(eventData); + + }, kvp => + { + if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapAfterPublish)) + { + Assert.NotNull(kvp.Value); + Assert.IsType(kvp.Value); + Assert.Equal(operationId, ((BrokerPublishEndEventData)kvp.Value).OperationId); + Assert.Equal(TimeSpan.FromMinutes(1), ((BrokerPublishEndEventData)kvp.Value).Duration); + } + }); + } + + [Fact] + public void WritePublishErrorTest() + { + Guid operationId = Guid.NewGuid(); + var ex = new Exception("WritePublishErrorTest"); + DiagnosticsWapper(() => + { + var eventData = new BrokerPublishErrorEventData(operationId, "", "", "", "", ex, DateTimeOffset.UtcNow, default(TimeSpan)); + s_diagnosticListener.WritePublishError(eventData); + + }, kvp => + { + if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapErrorPublish)) + { + Assert.NotNull(kvp.Value); + Assert.IsType(kvp.Value); + Assert.Equal(operationId, ((BrokerPublishErrorEventData)kvp.Value).OperationId); + Assert.Equal(ex, ((BrokerPublishErrorEventData)kvp.Value).Exception); + } + }); + } + + [Fact] + public void WriteConsumeBeforeTest() + { + Guid operationId = Guid.NewGuid(); + + DiagnosticsWapper(() => + { + var eventData = new BrokerConsumeEventData(operationId, "", "", "", "", DateTimeOffset.UtcNow); + s_diagnosticListener.WriteConsumeBefore(eventData); + + }, kvp => + { + if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapBeforeConsume)) + { + Assert.NotNull(kvp.Value); + Assert.IsType(kvp.Value); + Assert.Equal(operationId, ((BrokerConsumeEventData)kvp.Value).OperationId); + } + }); + } + + [Fact] + public void WriteConsumeAfterTest() + { + Guid operationId = Guid.NewGuid(); + + DiagnosticsWapper(() => + { + var eventData = new BrokerConsumeEndEventData(operationId, "", "", "", "", DateTimeOffset.UtcNow, TimeSpan.FromMinutes(1)); + s_diagnosticListener.WriteConsumeAfter(eventData); + + }, kvp => + { + if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapAfterConsume)) + { + Assert.NotNull(kvp.Value); + Assert.IsType(kvp.Value); + Assert.Equal(operationId, ((BrokerConsumeEndEventData)kvp.Value).OperationId); + Assert.Equal(TimeSpan.FromMinutes(1), ((BrokerConsumeEndEventData)kvp.Value).Duration); + } + }); + } + + [Fact] + public void WriteConsumeErrorTest() + { + Guid operationId = Guid.NewGuid(); + var ex = new Exception("WriteConsumeErrorTest"); + DiagnosticsWapper(() => + { + var eventData = new BrokerConsumeErrorEventData(operationId, "", "", "", "", ex, DateTimeOffset.UtcNow, default(TimeSpan)); + s_diagnosticListener.WriteConsumeError(eventData); + + }, kvp => + { + if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapErrorPublish)) + { + Assert.NotNull(kvp.Value); + Assert.IsType(kvp.Value); + Assert.Equal(operationId, ((BrokerConsumeErrorEventData)kvp.Value).OperationId); + Assert.Equal(ex, ((BrokerConsumeErrorEventData)kvp.Value).Exception); + } + }); + } + + [Fact] + public void WriteSubscriberInvokeBeforeTest() + { + DiagnosticsWapper(() => + { + s_diagnosticListener.WriteSubscriberInvokeBefore(FackConsumerContext()); + + }, kvp => + { + if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapBeforeSubscriberInvoke)) + { + Assert.NotNull(kvp.Value); + Assert.IsType(kvp.Value); + } + }); + } + + [Fact] + public void WriteSubscriberInvokeAfterTest() + { + Guid operationId = Guid.NewGuid(); + + DiagnosticsWapper(() => + { + s_diagnosticListener.WriteSubscriberInvokeAfter(operationId, FackConsumerContext(), DateTimeOffset.Now, TimeSpan.FromMinutes(1)); + + }, kvp => + { + if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapAfterSubscriberInvoke)) + { + Assert.NotNull(kvp.Value); + Assert.IsType(kvp.Value); + Assert.Equal(operationId, ((SubscriberInvokeEndEventData)kvp.Value).OperationId); + + } + }); + } + + [Fact] + public void WriteSubscriberInvokeErrorTest() + { + Guid operationId = Guid.NewGuid(); + + var ex = new Exception("WriteConsumeErrorTest"); + DiagnosticsWapper(() => + { + s_diagnosticListener.WriteSubscriberInvokeError(operationId, FackConsumerContext(), ex, + DateTimeOffset.Now, TimeSpan.MaxValue); + }, kvp => + { + if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapErrorSubscriberInvoke)) + { + Assert.NotNull(kvp.Value); + Assert.IsType(kvp.Value); + Assert.Equal(operationId, ((SubscriberInvokeErrorEventData)kvp.Value).OperationId); + Assert.Equal(ex, ((SubscriberInvokeErrorEventData)kvp.Value).Exception); + } + }); + } + + private ConsumerContext FackConsumerContext() + { + //Mock description + var description = new ConsumerExecutorDescriptor + { + MethodInfo = GetType().GetMethod("WriteSubscriberInvokeAfterTest"), + Attribute = new CapSubscribeAttribute("xxx"), + ImplTypeInfo = GetType().GetTypeInfo() + }; + + //Mock messageContext + var messageContext = new MessageContext + { + Name= "Name", + Group= "Group", + Content = "Content" + }; + + return new ConsumerContext(description, messageContext); + } + + private void DiagnosticsWapper(Action operation, Action> assert, [CallerMemberName]string methodName = "") + { + FakeDiagnosticListenerObserver diagnosticListenerObserver = new FakeDiagnosticListenerObserver(assert); + + diagnosticListenerObserver.Enable(); + using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver)) + { + Console.WriteLine(string.Format("Test: {0} Enabled Listeners", methodName)); + operation(); + } + } + } +} diff --git a/test/DotNetCore.CAP.Test/FakeDiagnosticListenerObserver.cs b/test/DotNetCore.CAP.Test/FakeDiagnosticListenerObserver.cs new file mode 100644 index 0000000..81db2c8 --- /dev/null +++ b/test/DotNetCore.CAP.Test/FakeDiagnosticListenerObserver.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using DotNetCore.CAP.Diagnostics; + +namespace DotNetCore.CAP.Test +{ + public sealed class FakeDiagnosticListenerObserver : IObserver + { + private class FakeDiagnosticSourceWriteObserver : IObserver> + { + private readonly Action> _writeCallback; + + public FakeDiagnosticSourceWriteObserver(Action> writeCallback) + { + _writeCallback = writeCallback; + } + + public void OnCompleted() + { + } + + public void OnError(Exception error) + { + } + + public void OnNext(KeyValuePair value) + { + _writeCallback(value); + } + } + + private readonly Action> _writeCallback; + private bool _writeObserverEnabled; + + public FakeDiagnosticListenerObserver(Action> writeCallback) + { + _writeCallback = writeCallback; + } + + public void OnCompleted() + { + } + + public void OnError(Exception error) + { + } + + public void OnNext(DiagnosticListener value) + { + if (value.Name.Equals(CapDiagnosticListenerExtensions.DiagnosticListenerName)) + { + value.Subscribe(new FakeDiagnosticSourceWriteObserver(_writeCallback), IsEnabled); + } + } + + public void Enable() + { + _writeObserverEnabled = true; + } + public void Disable() + { + _writeObserverEnabled = false; + } + private bool IsEnabled(string s) + { + return _writeObserverEnabled; + } + } +} From 027156c5681b87f3a86761e0f62a9f1769576de4 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 1 May 2018 14:02:39 +0800 Subject: [PATCH 23/57] removed unused files. --- .../Processor/DefaultDispatcherTest.cs | 83 ------------------- 1 file changed, 83 deletions(-) delete mode 100644 test/DotNetCore.CAP.Test/Processor/DefaultDispatcherTest.cs diff --git a/test/DotNetCore.CAP.Test/Processor/DefaultDispatcherTest.cs b/test/DotNetCore.CAP.Test/Processor/DefaultDispatcherTest.cs deleted file mode 100644 index 1f3c77e..0000000 --- a/test/DotNetCore.CAP.Test/Processor/DefaultDispatcherTest.cs +++ /dev/null @@ -1,83 +0,0 @@ -//using System; -//using System.Threading; -//using System.Threading.Tasks; -//using DotNetCore.CAP.Models; -//using DotNetCore.CAP.Processor; -//using Microsoft.Extensions.DependencyInjection; -//using Microsoft.Extensions.Options; -//using Moq; -//using Xunit; - -//namespace DotNetCore.CAP.Test -//{ -// public class DefaultDispatcherTest -// { -// private CancellationTokenSource _cancellationTokenSource; -// private ProcessingContext _context; -// private IServiceProvider _provider; -// private Mock _mockStorageConnection; - -// public DefaultDispatcherTest() -// { -// _mockStorageConnection = new Mock(); - -// _cancellationTokenSource = new CancellationTokenSource(); - -// var services = new ServiceCollection(); -// services.AddLogging(); -// services.Configure>(x => { }); -// services.AddOptions(); -// services.AddSingleton(_mockStorageConnection.Object); -// _provider = services.BuildServiceProvider(); - -// _context = new ProcessingContext(_provider, _cancellationTokenSource.Token); -// } - -// [Fact] -// public void MockTest() -// { -// Assert.NotNull(_provider.GetServices()); -// } - -// [Fact] -// public async void ProcessAsync_CancellationTokenCancelled_ThrowsImmediately() -// { -// // Arrange -// _cancellationTokenSource.Cancel(); -// var fixture = Create(); - -// // Act -// await Assert.ThrowsAsync(() => fixture.ProcessAsync(_context)); -// } - -// [Fact] -// public async Task ProcessAsync() -// { -// // Arrange -// var job = new CapPublishedMessage -// { -// }; - -// var mockFetchedJob = Mock.Get(Mock.Of(fj => fj.MessageId == 42 && fj.MessageType == MessageType.Publish)); - -// _mockStorageConnection -// .Setup(m => m.FetchNextMessageAsync()) -// .ReturnsAsync(mockFetchedJob.Object).Verifiable(); - -// _mockQueueExecutor -// .Setup(x => x.ExecuteAsync(_mockStorageConnection.Object, mockFetchedJob.Object)) -// .Returns(Task.FromResult(OperateResult.Success)); - -// var fixture = Create(); - -// // Act -// await fixture.ProcessAsync(_context); - -// // Assert -// _mockStorageConnection.VerifyAll(); -// } - -// private DefaultDispatcher Create() -// => _provider.GetService(); -// } -//} \ No newline at end of file From d8570384fcdad3e37990e31fc45c30e9359592ca Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 1 May 2018 14:03:04 +0800 Subject: [PATCH 24/57] add unit tests for Helper.cs --- test/DotNetCore.CAP.Test/HelperTest.cs | 154 +++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 test/DotNetCore.CAP.Test/HelperTest.cs diff --git a/test/DotNetCore.CAP.Test/HelperTest.cs b/test/DotNetCore.CAP.Test/HelperTest.cs new file mode 100644 index 0000000..48ee66f --- /dev/null +++ b/test/DotNetCore.CAP.Test/HelperTest.cs @@ -0,0 +1,154 @@ +using System; +using System.Reflection; +using DotNetCore.CAP.Diagnostics; +using DotNetCore.CAP.Infrastructure; +using Newtonsoft.Json.Linq; +using Xunit; + +namespace DotNetCore.CAP.Test +{ + public class HelperTest + { + + [Fact] + public void ToTimestampTest() + { + //Arrange + var time = DateTime.Parse("2018-01-01 00:00:00"); + + //Act + var result = Helper.ToTimestamp(time); + + //Assert + Assert.Equal(1514764800, result); + } + + [Fact] + public void FromTimestampTest() + { + //Arrange + var time = DateTime.Parse("2018-01-01 00:00:00"); + + //Act + var result = Helper.FromTimestamp(1514764800); + + //Assert + Assert.Equal(time, result); + } + + [Fact] + public void IsControllerTest() + { + //Arrange + var typeInfo = typeof(HomeController).GetTypeInfo(); + + //Act + var result = Helper.IsController(typeInfo); + + //Assert + Assert.True(result); + } + + [Theory] + [InlineData(typeof(string))] + [InlineData(typeof(decimal))] + [InlineData(typeof(DateTime))] + [InlineData(typeof(DateTimeOffset))] + [InlineData(typeof(Guid))] + [InlineData(typeof(TimeSpan))] + [InlineData(typeof(Uri))] + public void IsSimpleTypeTest(Type type) + { + //Act + var result = Helper.IsComplexType(type); + + //Assert + Assert.False(result); + } + + [Theory] + [InlineData(typeof(HomeController))] + [InlineData(typeof(Exception))] + [InlineData(typeof(Person))] + public void IsComplexTypeTest(Type type) + { + //Act + var result = Helper.IsComplexType(type); + + //Assert + Assert.True(result); + } + + [Fact] + public void AddExceptionPropertyTest() + { + //Arrange + var json = "{}"; + var exception = new Exception("Test Exception Message") + { + Source = "Test Source", + InnerException = { } + }; + + var expected = new + { + ExceptionMessage = new + { + Source = "Test Source", + Message = "Test Exception Message", + InnerMessage = new { } + } + }; + + //Act + var result = Helper.AddExceptionProperty(json, exception); + + //Assert + var jObj = JObject.Parse(result); + Assert.Equal(jObj["ExceptionMessage"]["Source"].Value(), expected.ExceptionMessage.Source); + Assert.Equal(jObj["ExceptionMessage"]["Message"].Value(), expected.ExceptionMessage.Message); + } + + [Theory] + [InlineData("10.0.0.1")] + [InlineData("172.16.0.1")] + [InlineData("192.168.1.1")] + public void IsInnerIPTest(string ipAddress) + { + Assert.True(Helper.IsInnerIP(ipAddress)); + } + + [Fact] + public void AddTracingHeaderPropertyTest() + { + //Arrange + var json = "{}"; + var header = new TracingHeaders { { "key", "value" } }; + + //Act + var result = Helper.AddTracingHeaderProperty(json, header); + + //Assert + var expected = "{\"TracingHeaders\":{\"key\":\"value\"}}"; + Assert.Equal(expected, result); + } + + [Fact] + public void TryExtractTracingHeadersTest() + { + //Arrange + var json = "{\"TracingHeaders\":{\"key\":\"value\"}}"; + TracingHeaders header = null; + string removedHeadersJson = ""; + + //Act + var result = Helper.TryExtractTracingHeaders(json, out header, out removedHeadersJson); + + //Assert + Assert.True(result); + Assert.NotNull(header); + Assert.Single(header); + Assert.Equal("{}", removedHeadersJson); + } + } +} From 1320a5428a2136f2d3f0b163055ff1ef5e90809f Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 1 May 2018 14:05:17 +0800 Subject: [PATCH 25/57] modify version to 2.2.3 --- build/version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/version.props b/build/version.props index ae5b04f..dcd0b81 100644 --- a/build/version.props +++ b/build/version.props @@ -2,7 +2,7 @@ 2 2 - 2 + 3 $(VersionMajor).$(VersionMinor).$(VersionPatch) From 05f6e66169ad17914e8f030e0351df239089e495 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 4 May 2018 19:29:15 +0800 Subject: [PATCH 26/57] Modify logs content. --- src/DotNetCore.CAP/ISubscribeExecutor.Default.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs b/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs index 92f988e..fe03a15 100644 --- a/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs +++ b/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs @@ -72,7 +72,7 @@ namespace DotNetCore.CAP } catch (Exception ex) { - _logger.ExceptionOccuredWhileExecuting(message.Name, ex); + _logger.LogError(ex, $"An exception occurred while executing the subscription method. Topic:{message.Name}, Id:{message.Id}"); await SetFailedState(message, ex, out bool stillRetry); if (stillRetry) From 1d7f2b19e65a2d4dafa615c265677ef83f90ef5e Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 4 May 2018 19:29:37 +0800 Subject: [PATCH 27/57] refactor and modify logs content. --- src/DotNetCore.CAP/Processor/IDispatcher.Default.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/DotNetCore.CAP/Processor/IDispatcher.Default.cs b/src/DotNetCore.CAP/Processor/IDispatcher.Default.cs index 95e9cdb..433c01b 100644 --- a/src/DotNetCore.CAP/Processor/IDispatcher.Default.cs +++ b/src/DotNetCore.CAP/Processor/IDispatcher.Default.cs @@ -65,7 +65,7 @@ namespace DotNetCore.CAP.Processor } catch (Exception ex) { - _logger.ExceptionOccuredWhileExecuting(message.Name, ex); + _logger.LogError(ex, $"An exception occurred when sending a message to the MQ. Topic:{message.Name}, Id:{message.Id}"); } } } @@ -82,14 +82,7 @@ namespace DotNetCore.CAP.Processor { foreach (var message in _receivedMessageQueue.GetConsumingEnumerable(_cts.Token)) { - try - { - _executor.ExecuteAsync(message); - } - catch (Exception ex) - { - _logger.ExceptionOccuredWhileExecuting(message.Name, ex); - } + _executor.ExecuteAsync(message); } } catch (OperationCanceledException) From 8e7435d48c7a6521a5cf3bb6899b76acb793ce6a Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 4 May 2018 19:29:52 +0800 Subject: [PATCH 28/57] remove some log items. --- src/DotNetCore.CAP/LoggerExtensions.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/DotNetCore.CAP/LoggerExtensions.cs b/src/DotNetCore.CAP/LoggerExtensions.cs index a0096e6..36b3570 100644 --- a/src/DotNetCore.CAP/LoggerExtensions.cs +++ b/src/DotNetCore.CAP/LoggerExtensions.cs @@ -18,7 +18,6 @@ namespace DotNetCore.CAP private static readonly Action _consumerFailedWillRetry; private static readonly Action _consumerExecuted; private static readonly Action _senderRetrying; - private static readonly Action _exceptionOccuredWhileExecuting; private static readonly Action _messageHasBeenSent; private static readonly Action _messagePublishException; @@ -73,12 +72,7 @@ namespace DotNetCore.CAP _consumerFailedWillRetry = LoggerMessage.Define( LogLevel.Warning, 2, - "Consumer failed to execute. Will retry."); - - _exceptionOccuredWhileExecuting = LoggerMessage.Define( - LogLevel.Error, - 6, - "An exception occured while trying to store a message. message id: {MessageId}"); + "Consumer failed to execute. Will retry."); _messageHasBeenSent = LoggerMessage.Define( LogLevel.Debug, @@ -136,11 +130,6 @@ namespace DotNetCore.CAP _expectedOperationCanceledException(logger, ex.Message, ex); } - public static void ExceptionOccuredWhileExecuting(this ILogger logger, string messageId, Exception ex) - { - _exceptionOccuredWhileExecuting(logger, messageId, ex); - } - public static void ModelBinderFormattingException(this ILogger logger, string methodName, string parameterName, string content, Exception ex) { From 7add30f85fee37156b9cd708c17ad865b9b1466b Mon Sep 17 00:00:00 2001 From: AlexLEWIS Date: Sun, 6 May 2018 09:49:14 +0800 Subject: [PATCH 29/57] Update badge to NCC (#128) * Update badge of NCC * Fixed a markdown syntax error in readme file --- README.md | 2 +- README.zh-cn.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cd25182..4dbadde 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![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/) [![NuGet Preview](https://img.shields.io/nuget/vpre/DotNetCore.CAP.svg?label=nuget-pre)](https://www.nuget.org/packages/DotNetCore.CAP/) -[![Member project of .NET China Foundation](https://img.shields.io/badge/member_project_of-.NET_CHINA-red.svg?style=flat&colorB=9E20C8)](https://github.com/dotnetcore) +[![Member project of .NET Core Community](https://img.shields.io/badge/member%20project%20of-NCC-9e20c9.svg)](https://github.com/dotnetcore) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/dotnetcore/CAP/master/LICENSE.txt) CAP is a library based on .Net standard, which is a solution to deal with distributed transactions, also has the function of EventBus, it is lightweight, easy to use, and efficiently. diff --git a/README.zh-cn.md b/README.zh-cn.md index 8ceb14b..639e4c5 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -3,7 +3,7 @@ [![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/) [![NuGet Preview](https://img.shields.io/nuget/vpre/DotNetCore.CAP.svg?label=nuget-pre)](https://www.nuget.org/packages/DotNetCore.CAP/) -[![Member project of .NET China Foundation](https://img.shields.io/badge/member_project_of-.NET_CHINA-red.svg?style=flat&colorB=9E20C8)](https://github.com/dotnetcore) +[![Member project of .NET Core Community](https://img.shields.io/badge/member%20project%20of-NCC-9e20c9.svg)](https://github.com/dotnetcore) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/dotnetcore/CAP/master/LICENSE.txt) CAP 是一个基于 .NET Standard 的 C# 库,它是一种处理分布式事务的解决方案,同样具有 EventBus 的功能,它具有轻量级、易使用、高性能等特点。 From a7c5dbe69447e0049f9517262696b769a9505db1 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Mon, 7 May 2018 17:10:08 +0800 Subject: [PATCH 30/57] add github issue template. --- .github/ISSUE_TEMPLATE | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE new file mode 100644 index 0000000..6cff5d2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE @@ -0,0 +1,40 @@ + + +Please answer these questions before submitting your issue. + +- Why do you submit this issue? +- [ ] Question or discussion +- [ ] Bug +- [ ] Requirement +- [ ] Feature or performance improvement + +___ +### Question +- What do you want to know? + +___ +### Bug +- Which version of SkyWalking, OS and JRE? + +- Which company or project? + +- What happen? +If possible, provide a way for reproducing the error. e.g. demo application, component version. + +___ +### Requirement or improvement +- Please describe about your requirements or improvement suggestions. \ No newline at end of file From 31a09d2b0df7518b6e0c57da15f577d79b6833bc Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 8 May 2018 09:31:14 +0800 Subject: [PATCH 31/57] update issue template. --- .github/ISSUE_TEMPLATE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE index 6cff5d2..66cdc24 100644 --- a/.github/ISSUE_TEMPLATE +++ b/.github/ISSUE_TEMPLATE @@ -28,7 +28,7 @@ ___ ___ ### Bug -- Which version of SkyWalking, OS and JRE? +- Which version of CAP, OS and .NET Core? - Which company or project? From 120b794645d28cae5a6be702b492ee4c4b217664 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 9 May 2018 20:59:07 +0800 Subject: [PATCH 32/57] Fixed exception thrown when terminate the program with Ctrl+C. (#130) --- CAP.sln | 1 + .../Processor/IProcessingServer.Cap.cs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CAP.sln b/CAP.sln index 952416d..828d82a 100644 --- a/CAP.sln +++ b/CAP.sln @@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution CHANGELOG.md = CHANGELOG.md CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md ConfigureMSDTC.ps1 = ConfigureMSDTC.ps1 + .github\ISSUE_TEMPLATE = .github\ISSUE_TEMPLATE LICENSE.txt = LICENSE.txt README.md = README.md README.zh-cn.md = README.zh-cn.md diff --git a/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs b/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs index b9d8802..551556e 100644 --- a/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs +++ b/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs @@ -57,13 +57,14 @@ namespace DotNetCore.CAP.Processor return; } - _disposed = true; - - _logger.ServerShuttingDown(); - _cts.Cancel(); try { - _compositeTask.Wait((int) TimeSpan.FromSeconds(10).TotalMilliseconds); + _disposed = true; + + _logger.ServerShuttingDown(); + _cts.Cancel(); + + _compositeTask?.Wait((int)TimeSpan.FromSeconds(10).TotalMilliseconds); } catch (AggregateException ex) { @@ -73,6 +74,10 @@ namespace DotNetCore.CAP.Processor _logger.ExpectedOperationCanceledException(innerEx); } } + catch (Exception ex) + { + _logger.LogWarning(ex, "An exception was occured when disposing..."); + } } private IProcessor InfiniteRetry(IProcessor inner) From 0d24027a301df3b535c43205dbe4fdee178dca8e Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 17 May 2018 14:28:45 +0800 Subject: [PATCH 33/57] update samples. --- samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj | 3 +-- samples/Sample.Kafka.MySql/Startup.cs | 4 ++-- samples/Sample.RabbitMQ.MySql/AppDbContext.cs | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj b/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj index 88c0c1d..bf80ce5 100644 --- a/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj +++ b/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj @@ -9,9 +9,8 @@ - + - diff --git a/samples/Sample.Kafka.MySql/Startup.cs b/samples/Sample.Kafka.MySql/Startup.cs index 419e48e..59c4636 100644 --- a/samples/Sample.Kafka.MySql/Startup.cs +++ b/samples/Sample.Kafka.MySql/Startup.cs @@ -10,8 +10,8 @@ namespace Sample.Kafka.MySql { services.AddCap(x => { - x.UseMySql("Server=192.168.10.110;Database=testcap;UserId=root;Password=123123;"); - x.UseKafka("192.168.10.110:9092"); + x.UseMySql("Server=localhost;Database=testcap;UserId=root;Password=123123;"); + x.UseKafka("localhost:9092"); x.UseDashboard(); }); diff --git a/samples/Sample.RabbitMQ.MySql/AppDbContext.cs b/samples/Sample.RabbitMQ.MySql/AppDbContext.cs index ec83423..d960a8f 100644 --- a/samples/Sample.RabbitMQ.MySql/AppDbContext.cs +++ b/samples/Sample.RabbitMQ.MySql/AppDbContext.cs @@ -6,7 +6,7 @@ namespace Sample.RabbitMQ.MySql { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseMySql("Server=192.168.10.110;Database=testcap;UserId=root;Password=123123;"); + optionsBuilder.UseMySql("Server=localhost;Database=testcap;UserId=root;Password=123123;"); } } } From 6c1cf7fb576d1b3bf19ff7f0eb41d4da999f9a5a Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 17 May 2018 14:29:18 +0800 Subject: [PATCH 34/57] upgrade MySqlConnector nuget package. --- src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj | 2 +- test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj index 38482c6..1e85be1 100644 --- a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj +++ b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj @@ -17,7 +17,7 @@ - + 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 31710c4..f96229e 100644 --- a/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj +++ b/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj @@ -16,7 +16,7 @@ - + From f39cd633fb67951261f36673d35c926730fc1a05 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 22 May 2018 19:36:26 +0800 Subject: [PATCH 35/57] optimized logging content. --- src/DotNetCore.CAP/LoggerExtensions.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DotNetCore.CAP/LoggerExtensions.cs b/src/DotNetCore.CAP/LoggerExtensions.cs index 36b3570..7ff8cf4 100644 --- a/src/DotNetCore.CAP/LoggerExtensions.cs +++ b/src/DotNetCore.CAP/LoggerExtensions.cs @@ -26,7 +26,7 @@ namespace DotNetCore.CAP _serverStarting = LoggerMessage.Define( LogLevel.Debug, 1, - "Starting the processing server."); + "Starting the processors."); _processorsStartingError = LoggerMessage.Define( LogLevel.Error, @@ -36,7 +36,7 @@ namespace DotNetCore.CAP _serverShuttingDown = LoggerMessage.Define( LogLevel.Information, 2, - "Shutting down the processing server..."); + "Processors is shutting down..."); _expectedOperationCanceledException = LoggerMessage.Define( LogLevel.Warning, @@ -60,7 +60,7 @@ namespace DotNetCore.CAP ); _senderRetrying = LoggerMessage.Define( - LogLevel.Debug, + LogLevel.Information, 3, "The {Retries}th retrying send a message failed. message id: {MessageId} "); @@ -72,7 +72,7 @@ namespace DotNetCore.CAP _consumerFailedWillRetry = LoggerMessage.Define( LogLevel.Warning, 2, - "Consumer failed to execute. Will retry."); + "Consumer failed to execute, it will be retry."); _messageHasBeenSent = LoggerMessage.Define( LogLevel.Debug, From 239b849c57a299d8dcc55eb7607a3f6f7ebaf205 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Mon, 21 May 2018 19:37:00 +0800 Subject: [PATCH 36/57] add cap started and shotdown log. --- src/DotNetCore.CAP/IBootstrapper.Default.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DotNetCore.CAP/IBootstrapper.Default.cs b/src/DotNetCore.CAP/IBootstrapper.Default.cs index d89986a..9af8f2e 100644 --- a/src/DotNetCore.CAP/IBootstrapper.Default.cs +++ b/src/DotNetCore.CAP/IBootstrapper.Default.cs @@ -59,6 +59,8 @@ namespace DotNetCore.CAP private async Task BootstrapTaskAsync() { + _logger.LogInformation("### CAP starting..."); + await Storage.InitializeAsync(_cts.Token); if (_cts.IsCancellationRequested) @@ -83,6 +85,8 @@ namespace DotNetCore.CAP _ctsRegistration.Dispose(); _cts.Dispose(); + + _logger.LogInformation("### CAP started!"); } protected virtual Task BootstrapCoreAsync() From 83c8ccf889648979706720ce0690b80a8535db63 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sun, 20 May 2018 19:37:28 +0800 Subject: [PATCH 37/57] rename processor. --- src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs b/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs index 551556e..a05c302 100644 --- a/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs +++ b/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs @@ -76,7 +76,11 @@ namespace DotNetCore.CAP.Processor } catch (Exception ex) { - _logger.LogWarning(ex, "An exception was occured when disposing..."); + _logger.LogWarning(ex, "An exception was occured when disposing."); + } + finally + { + _logger.LogInformation("### CAP shutdown!"); } } @@ -90,7 +94,7 @@ namespace DotNetCore.CAP.Processor var returnedProcessors = new List { _provider.GetRequiredService(), - _provider.GetRequiredService() + _provider.GetRequiredService() }; return returnedProcessors.ToArray(); From 09cd281701d554a72e8b48329fd53032a3d89996 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sat, 19 May 2018 19:38:00 +0800 Subject: [PATCH 38/57] rename mysql processor --- src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs b/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs index 0bf0c2b..0c58540 100644 --- a/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs @@ -26,7 +26,7 @@ namespace DotNetCore.CAP services.AddSingleton(); services.AddScoped(); services.AddScoped(); - services.AddTransient(); + services.AddTransient(); AddSingletionMySqlOptions(services); } From d46c0954e0369b59ed82d28fb89c358206ef6fc0 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sun, 13 May 2018 19:38:27 +0800 Subject: [PATCH 39/57] rename postgresql processor. --- .../CAP.PostgreSqlCapOptionsExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs b/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs index 62af675..edc1729 100644 --- a/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs @@ -26,7 +26,7 @@ namespace DotNetCore.CAP services.AddSingleton(); services.AddScoped(); services.AddScoped(); - services.AddTransient(); + services.AddTransient(); AddSingletonPostgreSqlOptions(services); } From 4e6c0004c1e506ede1aafab507218a844876efdd Mon Sep 17 00:00:00 2001 From: Savorboard Date: Mon, 14 May 2018 19:38:49 +0800 Subject: [PATCH 40/57] rename sqlserver processor --- .../CAP.SqlServerCapOptionsExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs b/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs index d536647..91e04f7 100644 --- a/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs @@ -26,7 +26,7 @@ namespace DotNetCore.CAP services.AddSingleton(); services.AddScoped(); services.AddScoped(); - services.AddTransient(); + services.AddTransient(); AddSqlServerOptions(services); } From d102100bd98e6ca5ca69f38ed97c2cfcbf329b35 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 6 Apr 2018 19:40:00 +0800 Subject: [PATCH 41/57] rename IAdditionalProcessor to ICollectProcessor --- .../Processor/{IAdditionalProcessor.cs => ICollectProcessor.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/DotNetCore.CAP/Processor/{IAdditionalProcessor.cs => ICollectProcessor.cs} (78%) diff --git a/src/DotNetCore.CAP/Processor/IAdditionalProcessor.cs b/src/DotNetCore.CAP/Processor/ICollectProcessor.cs similarity index 78% rename from src/DotNetCore.CAP/Processor/IAdditionalProcessor.cs rename to src/DotNetCore.CAP/Processor/ICollectProcessor.cs index 51fc1c3..9fd2625 100644 --- a/src/DotNetCore.CAP/Processor/IAdditionalProcessor.cs +++ b/src/DotNetCore.CAP/Processor/ICollectProcessor.cs @@ -3,7 +3,7 @@ namespace DotNetCore.CAP.Processor { - public interface IAdditionalProcessor : IProcessor + public interface ICollectProcessor : IProcessor { } } \ No newline at end of file From 41b64262bcd658f5239fbf1c134203c8f5a54f3d Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sat, 21 Apr 2018 19:40:55 +0800 Subject: [PATCH 42/57] rename file. --- ...nalProcessor.Default.cs => ICollectProcessor.MySql.cs} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/DotNetCore.CAP.MySql/{IAdditionalProcessor.Default.cs => ICollectProcessor.MySql.cs} (88%) diff --git a/src/DotNetCore.CAP.MySql/IAdditionalProcessor.Default.cs b/src/DotNetCore.CAP.MySql/ICollectProcessor.MySql.cs similarity index 88% rename from src/DotNetCore.CAP.MySql/IAdditionalProcessor.Default.cs rename to src/DotNetCore.CAP.MySql/ICollectProcessor.MySql.cs index fd892cb..4cd0a23 100644 --- a/src/DotNetCore.CAP.MySql/IAdditionalProcessor.Default.cs +++ b/src/DotNetCore.CAP.MySql/ICollectProcessor.MySql.cs @@ -10,7 +10,7 @@ using MySql.Data.MySqlClient; namespace DotNetCore.CAP.MySql { - internal class DefaultAdditionalProcessor : IAdditionalProcessor + internal class MySqlCollectProcessor : ICollectProcessor { private const int MaxBatch = 1000; private readonly TimeSpan _delay = TimeSpan.FromSeconds(1); @@ -18,7 +18,7 @@ namespace DotNetCore.CAP.MySql private readonly MySqlOptions _options; private readonly TimeSpan _waitingInterval = TimeSpan.FromMinutes(5); - public DefaultAdditionalProcessor(ILogger logger, + public MySqlCollectProcessor(ILogger logger, MySqlOptions mysqlOptions) { _logger = logger; @@ -27,8 +27,6 @@ namespace DotNetCore.CAP.MySql public async Task ProcessAsync(ProcessingContext context) { - _logger.LogDebug("Collecting expired entities."); - var tables = new[] { $"{_options.TableNamePrefix}.published", @@ -37,6 +35,8 @@ namespace DotNetCore.CAP.MySql foreach (var table in tables) { + _logger.LogDebug($"Collecting expired data from table [{table}]."); + int removedCount; do { From ea8c82fcc679dd7886b74dd0fbc33f7b7481db65 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sun, 22 Apr 2018 19:41:06 +0800 Subject: [PATCH 43/57] rename file. --- ...cessor.Default.cs => ICollectlProcessor.PostgreSql.cs} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/DotNetCore.CAP.PostgreSql/{IAdditionalProcessor.Default.cs => ICollectlProcessor.PostgreSql.cs} (87%) diff --git a/src/DotNetCore.CAP.PostgreSql/IAdditionalProcessor.Default.cs b/src/DotNetCore.CAP.PostgreSql/ICollectlProcessor.PostgreSql.cs similarity index 87% rename from src/DotNetCore.CAP.PostgreSql/IAdditionalProcessor.Default.cs rename to src/DotNetCore.CAP.PostgreSql/ICollectlProcessor.PostgreSql.cs index ef606eb..d82f0b8 100644 --- a/src/DotNetCore.CAP.PostgreSql/IAdditionalProcessor.Default.cs +++ b/src/DotNetCore.CAP.PostgreSql/ICollectlProcessor.PostgreSql.cs @@ -10,7 +10,7 @@ using Npgsql; namespace DotNetCore.CAP.PostgreSql { - internal class DefaultAdditionalProcessor : IAdditionalProcessor + internal class PostgreSqlCollectProcessor : ICollectProcessor { private const int MaxBatch = 1000; @@ -24,7 +24,7 @@ namespace DotNetCore.CAP.PostgreSql private readonly PostgreSqlOptions _options; private readonly TimeSpan _waitingInterval = TimeSpan.FromMinutes(5); - public DefaultAdditionalProcessor(ILogger logger, + public PostgreSqlCollectProcessor(ILogger logger, PostgreSqlOptions sqlServerOptions) { _logger = logger; @@ -33,10 +33,10 @@ namespace DotNetCore.CAP.PostgreSql public async Task ProcessAsync(ProcessingContext context) { - _logger.LogDebug("Collecting expired entities."); - foreach (var table in Tables) { + _logger.LogDebug($"Collecting expired data from table [{_options.Schema}].[{table}]."); + var removedCount = 0; do { From be65af4158af2fb1451d2b5efc2cf477407d9181 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Mon, 23 Apr 2018 19:41:15 +0800 Subject: [PATCH 44/57] rename file. --- ...rocessor.Default.cs => ICollectProcessor.SqlServer.cs} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/DotNetCore.CAP.SqlServer/{IAdditionalProcessor.Default.cs => ICollectProcessor.SqlServer.cs} (87%) diff --git a/src/DotNetCore.CAP.SqlServer/IAdditionalProcessor.Default.cs b/src/DotNetCore.CAP.SqlServer/ICollectProcessor.SqlServer.cs similarity index 87% rename from src/DotNetCore.CAP.SqlServer/IAdditionalProcessor.Default.cs rename to src/DotNetCore.CAP.SqlServer/ICollectProcessor.SqlServer.cs index 8e344d6..c7a4d03 100644 --- a/src/DotNetCore.CAP.SqlServer/IAdditionalProcessor.Default.cs +++ b/src/DotNetCore.CAP.SqlServer/ICollectProcessor.SqlServer.cs @@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging; namespace DotNetCore.CAP.SqlServer { - public class DefaultAdditionalProcessor : IAdditionalProcessor + public class SqlServerCollectProcessor : ICollectProcessor { private const int MaxBatch = 1000; @@ -24,7 +24,7 @@ namespace DotNetCore.CAP.SqlServer private readonly SqlServerOptions _options; private readonly TimeSpan _waitingInterval = TimeSpan.FromMinutes(5); - public DefaultAdditionalProcessor(ILogger logger, + public SqlServerCollectProcessor(ILogger logger, SqlServerOptions sqlServerOptions) { _logger = logger; @@ -33,10 +33,10 @@ namespace DotNetCore.CAP.SqlServer public async Task ProcessAsync(ProcessingContext context) { - _logger.LogDebug("Collecting expired entities."); - foreach (var table in Tables) { + _logger.LogDebug($"Collecting expired data from table [{_options.Schema}].[{table}]."); + int removedCount; do { From f2140f0734e3aa485a85da90fe7a95bd783140a5 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 23 May 2018 19:42:02 +0800 Subject: [PATCH 45/57] add appsettings.json to sample. --- samples/Sample.Kafka.MySql/appsettings.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 samples/Sample.Kafka.MySql/appsettings.json diff --git a/samples/Sample.Kafka.MySql/appsettings.json b/samples/Sample.Kafka.MySql/appsettings.json new file mode 100644 index 0000000..20aa907 --- /dev/null +++ b/samples/Sample.Kafka.MySql/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug" + } + } +} From d38119575c5247bda8dc1ab775c098517ee60903 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 24 May 2018 15:12:17 +0800 Subject: [PATCH 46/57] refactor --- src/DotNetCore.CAP/Internal/IConsumerServiceSelector.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.cs b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.cs index 3c1dc94..0b53af7 100644 --- a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.cs +++ b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.cs @@ -22,8 +22,6 @@ namespace DotNetCore.CAP.Internal /// /// topic or exchange router key. /// the set of candidates. - /// - ConsumerExecutorDescriptor - SelectBestCandidate(string key, IReadOnlyList candidates); + ConsumerExecutorDescriptor SelectBestCandidate(string key, IReadOnlyList candidates); } } \ No newline at end of file From 19ed887bfa1e9ca23462151e0eafe2efd54ef54d Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 24 May 2018 15:17:59 +0800 Subject: [PATCH 47/57] add unit tests for ConsumerServiceSelector --- .../ConsumerServiceSelectorTest.cs | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs b/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs index 71154b5..8f255a4 100644 --- a/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs +++ b/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs @@ -28,7 +28,7 @@ namespace DotNetCore.CAP.Test var selector = _provider.GetRequiredService(); var candidates = selector.SelectCandidates(); - Assert.Equal(2, candidates.Count); + Assert.Equal(6, candidates.Count); } [Fact] @@ -42,6 +42,66 @@ namespace DotNetCore.CAP.Test Assert.NotNull(bestCandidates.MethodInfo); Assert.Equal(typeof(Task), bestCandidates.MethodInfo.ReturnType); } + + + [Theory] + [InlineData("Candidates.Asterisk")] + [InlineData("candidates.Asterisk")] + [InlineData("AAA.BBB.Asterisk")] + [InlineData("aaa.bbb.Asterisk")] + public void CanFindAsteriskTopic(string topic) + { + var selector = _provider.GetRequiredService(); + var candidates = selector.SelectCandidates(); + + var bestCandidates = selector.SelectBestCandidate(topic, candidates); + Assert.NotNull(bestCandidates); + } + + [Theory] + [InlineData("Candidates.Asterisk.AAA")] + [InlineData("AAA.BBB.CCC.Asterisk")] + [InlineData("aaa.BBB.ccc.Asterisk")] + [InlineData("Asterisk.aaa.bbb")] + public void CanNotFindAsteriskTopic(string topic) + { + var selector = _provider.GetRequiredService(); + var candidates = selector.SelectCandidates(); + + var bestCandidates = selector.SelectBestCandidate(topic, candidates); + Assert.Null(bestCandidates); + } + + [Theory] + [InlineData("Candidates.Pound.AAA")] + [InlineData("Candidates.Pound.AAA.BBB")] + [InlineData("AAA.Pound")] + [InlineData("aaa.Pound")] + [InlineData("aaa.bbb.Pound")] + [InlineData("aaa.BBB.Pound")] + public void CanFindPoundTopic(string topic) + { + var selector = _provider.GetRequiredService(); + var candidates = selector.SelectCandidates(); + + var bestCandidates = selector.SelectBestCandidate(topic, candidates); + Assert.NotNull(bestCandidates); + } + + [Theory] + [InlineData("Pound")] + [InlineData("aaa.Pound.AAA.BBB")] + [InlineData("Pound.AAA")] + [InlineData("Pound.aaa")] + [InlineData("AAA.Pound.aaa")] + public void CanNotFindPoundTopic(string topic) + { + var selector = _provider.GetRequiredService(); + var candidates = selector.SelectCandidates(); + + var bestCandidates = selector.SelectBestCandidate(topic, candidates); + Assert.Null(bestCandidates); + } } public class CandidatesTopic : TopicAttribute @@ -73,6 +133,21 @@ namespace DotNetCore.CAP.Test { Console.WriteLine("GetFoo2() method has bee excuted."); } + + [CandidatesTopic("*.*.Asterisk")] + [CandidatesTopic("*.Asterisk")] + public void GetFooAsterisk() + { + Console.WriteLine("GetFoo2Asterisk() method has bee excuted."); + } + + [CandidatesTopic("Candidates.Pound.#")] + [CandidatesTopic("#.Pound")] + public void GetFooPound() + { + Console.WriteLine("GetFoo2Pound() method has bee excuted."); + } + } public class CandidatesBarTest : IBarTest From 773e9428dbe6ea4ab23e02bd70cad4b600d45790 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 24 May 2018 15:20:45 +0800 Subject: [PATCH 48/57] support pattern matching for consumer. (#132) --- .../IConsumerServiceSelector.Default.cs | 94 ++++++++++++++++--- .../Internal/MethodMatcherCache.cs | 57 +---------- 2 files changed, 88 insertions(+), 63 deletions(-) diff --git a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs index 7bf92f3..f751499 100644 --- a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs +++ b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Text.RegularExpressions; using DotNetCore.CAP.Abstractions; using DotNetCore.CAP.Infrastructure; using Microsoft.Extensions.DependencyInjection; @@ -19,6 +20,8 @@ namespace DotNetCore.CAP.Internal { private readonly CapOptions _capOptions; private readonly IServiceProvider _serviceProvider; + private List> _asteriskList; + private List> _poundList; /// /// Creates a new . @@ -29,17 +32,6 @@ namespace DotNetCore.CAP.Internal _capOptions = capOptions; } - /// - /// Selects the best candidate from for - /// the - /// current message associated. - /// - public ConsumerExecutorDescriptor SelectBestCandidate(string key, - IReadOnlyList executeDescriptor) - { - return executeDescriptor.FirstOrDefault(x => x.Attribute.Name == key); - } - public IReadOnlyList SelectCandidates() { var executorDescriptorList = new List(); @@ -51,6 +43,26 @@ namespace DotNetCore.CAP.Internal return executorDescriptorList; } + public ConsumerExecutorDescriptor SelectBestCandidate(string key, IReadOnlyList executeDescriptor) + { + var result = MatchUsingName(key, executeDescriptor); + if (result != null) + { + return result; + } + + //[*] match with regex, i.e. foo.*.abc + result = MatchAsteriskUsingRegex(key, executeDescriptor); + if (result != null) + { + return result; + } + + //[#] match regex, i.e. foo.# + result = MatchPoundUsingRegex(key, executeDescriptor); + return result; + } + private IEnumerable FindConsumersFromInterfaceTypes( IServiceProvider provider) { @@ -130,5 +142,65 @@ namespace DotNetCore.CAP.Internal return descriptor; } + + private ConsumerExecutorDescriptor MatchUsingName(string key, IReadOnlyList executeDescriptor) + { + return executeDescriptor.FirstOrDefault(x => x.Attribute.Name == key); + } + + private ConsumerExecutorDescriptor MatchAsteriskUsingRegex(string key, IReadOnlyList executeDescriptor) + { + if (_asteriskList == null) + { + _asteriskList = executeDescriptor + .Where(x => x.Attribute.Name.IndexOf('*') >= 0) + .Select(x => new RegexExecuteDescriptor + { + Name = ("^" + x.Attribute.Name + "$").Replace("*", "[a-zA-Z]+").Replace(".", "\\."), + Descriptor = x + }).ToList(); + } + foreach (var red in _asteriskList) + { + if (Regex.IsMatch(key, red.Name, RegexOptions.Singleline)) + { + return red.Descriptor; + } + } + + return null; + } + + private ConsumerExecutorDescriptor MatchPoundUsingRegex(string key, IReadOnlyList executeDescriptor) + { + if (_poundList == null) + { + _poundList = executeDescriptor + .Where(x => x.Attribute.Name.IndexOf('#') >= 0) + .Select(x => new RegexExecuteDescriptor + { + Name = ("^" + x.Attribute.Name + "$").Replace("#", "[a-zA-Z\\.]+"), + Descriptor = x + }).ToList(); + } + + foreach (var red in _poundList) + { + if (Regex.IsMatch(key, red.Name, RegexOptions.Singleline)) + { + return red.Descriptor; + } + } + + return null; + } + + + private class RegexExecuteDescriptor + { + public string Name { get; set; } + + public T Descriptor { get; set; } + } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/Internal/MethodMatcherCache.cs b/src/DotNetCore.CAP/Internal/MethodMatcherCache.cs index d6b40ba..8ff25c7 100644 --- a/src/DotNetCore.CAP/Internal/MethodMatcherCache.cs +++ b/src/DotNetCore.CAP/Internal/MethodMatcherCache.cs @@ -11,21 +11,20 @@ namespace DotNetCore.CAP.Internal internal class MethodMatcherCache { private readonly IConsumerServiceSelector _selector; - private List _allTopics; public MethodMatcherCache(IConsumerServiceSelector selector) { _selector = selector; - Entries = new ConcurrentDictionary>(); + Entries = new ConcurrentDictionary>(); } - private ConcurrentDictionary> Entries { get; } + private ConcurrentDictionary> Entries { get; } /// /// Get a dictionary of candidates.In the dictionary, /// the Key is the CAPSubscribeAttribute Group, the Value for the current Group of candidates /// - public ConcurrentDictionary> GetCandidatesMethodsOfGroupNameGrouped() + public ConcurrentDictionary> GetCandidatesMethodsOfGroupNameGrouped() { if (Entries.Count != 0) { @@ -44,28 +43,6 @@ namespace DotNetCore.CAP.Internal return Entries; } - /// - /// Get a dictionary of specify topic candidates. - /// The Key is Group name, the value is specify topic candidates. - /// - /// message topic name - public IDictionary> GetTopicExector(string topicName) - { - if (Entries == null) - { - throw new ArgumentNullException(nameof(Entries)); - } - - var dic = new Dictionary>(); - foreach (var item in Entries) - { - var topicCandidates = item.Value.Where(x => x.Attribute.Name == topicName); - dic.Add(item.Key, topicCandidates.ToList()); - } - - return dic; - } - /// /// Attempts to get the topic exector associated with the specified topic name and group name from the /// . @@ -86,36 +63,12 @@ namespace DotNetCore.CAP.Internal if (Entries.TryGetValue(groupName, out var groupMatchTopics)) { - matchTopic = groupMatchTopics.FirstOrDefault(x => x.Attribute.Name == topicName); + matchTopic = _selector.SelectBestCandidate(topicName, groupMatchTopics); + return matchTopic != null; } return false; } - - /// - /// Get all subscribe topics name. - /// - public IEnumerable GetSubscribeTopics() - { - if (_allTopics != null) - { - return _allTopics; - } - - if (Entries == null) - { - throw new ArgumentNullException(nameof(Entries)); - } - - _allTopics = new List(); - - foreach (var descriptors in Entries.Values) - { - _allTopics.AddRange(descriptors.Select(x => x.Attribute.Name)); - } - - return _allTopics; - } } } \ No newline at end of file From b5a67fe0fae91f8487e944a2030ad09550144949 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 24 May 2018 18:01:22 +0800 Subject: [PATCH 49/57] update samples. --- samples/Sample.Kafka.MySql/nlog.config | 26 ------------------- .../Sample.RabbitMQ.MySql/appsettings.json | 8 ++++++ samples/Sample.RabbitMQ.MySql/nlog.config | 26 ------------------- 3 files changed, 8 insertions(+), 52 deletions(-) delete mode 100644 samples/Sample.Kafka.MySql/nlog.config create mode 100644 samples/Sample.RabbitMQ.MySql/appsettings.json delete mode 100644 samples/Sample.RabbitMQ.MySql/nlog.config diff --git a/samples/Sample.Kafka.MySql/nlog.config b/samples/Sample.Kafka.MySql/nlog.config deleted file mode 100644 index 5b91105..0000000 --- a/samples/Sample.Kafka.MySql/nlog.config +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/Sample.RabbitMQ.MySql/appsettings.json b/samples/Sample.RabbitMQ.MySql/appsettings.json new file mode 100644 index 0000000..20aa907 --- /dev/null +++ b/samples/Sample.RabbitMQ.MySql/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Debug" + } + } +} diff --git a/samples/Sample.RabbitMQ.MySql/nlog.config b/samples/Sample.RabbitMQ.MySql/nlog.config deleted file mode 100644 index bba5bea..0000000 --- a/samples/Sample.RabbitMQ.MySql/nlog.config +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 8b1ec942c4284bb052ceef34f6f99b4d9a627ae1 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 24 May 2018 18:01:54 +0800 Subject: [PATCH 50/57] refactoring log output. --- .../IConnectionPool.Default.cs | 14 ++++++++++---- .../IConnectionChannelPool.Default.cs | 14 +++++++++----- .../RabbitMQConsumerClient.cs | 4 ++-- src/DotNetCore.CAP/IConsumerHandler.Default.cs | 12 ++++++------ 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs b/src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs index 1993661..21b8398 100644 --- a/src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs +++ b/src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs @@ -6,23 +6,29 @@ using System.Collections.Concurrent; using System.Diagnostics; using System.Threading; using Confluent.Kafka; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace DotNetCore.CAP.Kafka { public class ConnectionPool : IConnectionPool, IDisposable { + private readonly ILogger _logger; private readonly Func _activator; - private readonly ConcurrentQueue _pool = new ConcurrentQueue(); + private readonly ConcurrentQueue _pool; private int _count; - private int _maxSize; - public ConnectionPool(KafkaOptions options) + public ConnectionPool(ILogger logger, KafkaOptions options) { + _logger = logger; + _pool = new ConcurrentQueue(); _maxSize = options.ConnectionPoolSize; _activator = CreateActivator(options); - ServersAddress = options.Servers; + + _logger.LogDebug("Kafka configuration of CAP :\r\n {0}", + JsonConvert.SerializeObject(options.AsKafkaConfig(), Formatting.Indented)); } public string ServersAddress { get; } diff --git a/src/DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs b/src/DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs index e650518..e15fdfa 100644 --- a/src/DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs +++ b/src/DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs @@ -6,6 +6,7 @@ using System.Collections.Concurrent; using System.Diagnostics; using System.Threading; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; using RabbitMQ.Client; namespace DotNetCore.CAP.RabbitMQ @@ -15,21 +16,24 @@ namespace DotNetCore.CAP.RabbitMQ private const int DefaultPoolSize = 15; private readonly Func _connectionActivator; private readonly ILogger _logger; - private readonly ConcurrentQueue _pool = new ConcurrentQueue(); + private readonly ConcurrentQueue _pool; private IConnection _connection; private int _count; private int _maxSize; - public ConnectionChannelPool(ILogger logger, - RabbitMQOptions options) + public ConnectionChannelPool(ILogger logger, RabbitMQOptions options) { _logger = logger; _maxSize = DefaultPoolSize; - + _pool = new ConcurrentQueue(); _connectionActivator = CreateConnection(options); + HostAddress = options.HostName + ":" + options.Port; Exchange = options.ExchangeName; + + _logger.LogDebug("RabbitMQ configuration of CAP :\r\n {0}", + JsonConvert.SerializeObject(options, Formatting.Indented)); } IModel IConnectionChannelPool.Rent() @@ -87,7 +91,7 @@ namespace DotNetCore.CAP.RabbitMQ private void RabbitMQ_ConnectionShutdown(object sender, ShutdownEventArgs e) { - _logger.LogWarning($"RabbitMQ client connection closed! {e}"); + _logger.LogWarning($"RabbitMQ client connection closed! --> {e.ReplyText}"); } public virtual IModel Rent() diff --git a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs index a34054f..972b6dd 100644 --- a/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs +++ b/src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs @@ -93,7 +93,7 @@ namespace DotNetCore.CAP.RabbitMQ _connection = _connectionChannelPool.GetConnection(); _channel = _connection.CreateModel(); - + _channel.ExchangeDeclare( _exchageName, RabbitMQOptions.ExchangeType, @@ -155,7 +155,7 @@ namespace DotNetCore.CAP.RabbitMQ var args = new LogMessageEventArgs { LogType = MqLogType.ConsumerShutdown, - Reason = e.ToString() + Reason = e.ReplyText }; OnLog?.Invoke(sender, args); } diff --git a/src/DotNetCore.CAP/IConsumerHandler.Default.cs b/src/DotNetCore.CAP/IConsumerHandler.Default.cs index 1d441ff..e2179ff 100644 --- a/src/DotNetCore.CAP/IConsumerHandler.Default.cs +++ b/src/DotNetCore.CAP/IConsumerHandler.Default.cs @@ -146,22 +146,22 @@ namespace DotNetCore.CAP switch (logmsg.LogType) { case MqLogType.ConsumerCancelled: - _logger.LogWarning("RabbitMQ consumer cancelled. reason: " + logmsg.Reason); + _logger.LogWarning("RabbitMQ consumer cancelled. --> " + logmsg.Reason); break; case MqLogType.ConsumerRegistered: - _logger.LogInformation("RabbitMQ consumer registered. " + logmsg.Reason); + _logger.LogInformation("RabbitMQ consumer registered. --> " + logmsg.Reason); break; case MqLogType.ConsumerUnregistered: - _logger.LogWarning("RabbitMQ consumer unregistered. reason: " + logmsg.Reason); + _logger.LogWarning("RabbitMQ consumer unregistered. --> " + logmsg.Reason); break; case MqLogType.ConsumerShutdown: - _logger.LogWarning("RabbitMQ consumer shutdown. reason:" + logmsg.Reason); + _logger.LogWarning("RabbitMQ consumer shutdown. --> " + logmsg.Reason); break; case MqLogType.ConsumeError: - _logger.LogError("Kakfa client consume error. reason:" + logmsg.Reason); + _logger.LogError("Kakfa client consume error. --> " + logmsg.Reason); break; case MqLogType.ServerConnError: - _logger.LogCritical("Kafka server connection error. reason:" + logmsg.Reason); + _logger.LogCritical("Kafka server connection error. --> " + logmsg.Reason); break; default: throw new ArgumentOutOfRangeException(); From fd19d977fd866bbe2d9a0663a6c9a5b255a3e4a7 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 5 Jun 2018 10:17:30 +0800 Subject: [PATCH 51/57] Upgrade samples to .net core 2.1 --- .../Controllers/ValuesController.cs | 2 +- samples/Sample.Kafka.MySql/Program.cs | 6 ------ .../Sample.Kafka.MySql/Sample.Kafka.MySql.csproj | 15 +++------------ .../Controllers/ValuesController.cs | 3 +-- samples/Sample.RabbitMQ.MySql/Program.cs | 6 ------ .../Sample.RabbitMQ.MySql.csproj | 12 +++--------- samples/Sample.RabbitMQ.MySql/Startup.cs | 3 --- 7 files changed, 8 insertions(+), 39 deletions(-) diff --git a/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs b/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs index 6f04946..21510bb 100644 --- a/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs +++ b/samples/Sample.Kafka.MySql/Controllers/ValuesController.cs @@ -34,7 +34,7 @@ namespace Sample.Kafka.MySql.Controllers return Ok("publish successful!"); } - [CapSubscribe("xxx.xxx.test2")] + [CapSubscribe("#.test2")] public void Test2(int value) { Console.WriteLine("Subscriber output message: " + value); diff --git a/samples/Sample.Kafka.MySql/Program.cs b/samples/Sample.Kafka.MySql/Program.cs index 976b20a..e7be245 100644 --- a/samples/Sample.Kafka.MySql/Program.cs +++ b/samples/Sample.Kafka.MySql/Program.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using NLog.Web; namespace Sample.Kafka.MySql { @@ -15,11 +14,6 @@ namespace Sample.Kafka.MySql public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() - .ConfigureLogging((hostingContext, builder) => - { - hostingContext.HostingEnvironment.ConfigureNLog("nlog.config"); - }) - .UseNLog() .Build(); } } \ No newline at end of file diff --git a/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj b/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj index bf80ce5..e4a70df 100644 --- a/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj +++ b/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj @@ -1,29 +1,20 @@  - netcoreapp2.0 + netcoreapp2.1 Sample.Kafka.MySql NU1701 NU1701 - + - - - - - + - - - PreserveNewest - - diff --git a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs index 1b47e5e..03f33c0 100644 --- a/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs +++ b/samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs @@ -25,7 +25,6 @@ namespace Sample.RabbitMQ.MySql.Controllers return Ok(); } - [Route("~/publish2")] public IActionResult PublishMessage2() { @@ -47,7 +46,7 @@ namespace Sample.RabbitMQ.MySql.Controllers } [NonAction] - [CapSubscribe("sample.rabbitmq.mysql")] + [CapSubscribe("#.rabbitmq.mysql")] public void ReceiveMessage(DateTime time) { Console.WriteLine("[sample.rabbitmq.mysql] message received: " + DateTime.Now + ",sent time: " + time); diff --git a/samples/Sample.RabbitMQ.MySql/Program.cs b/samples/Sample.RabbitMQ.MySql/Program.cs index 3cbbe15..4e25d5c 100644 --- a/samples/Sample.RabbitMQ.MySql/Program.cs +++ b/samples/Sample.RabbitMQ.MySql/Program.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using NLog.Web; namespace Sample.RabbitMQ.MySql { @@ -14,11 +13,6 @@ namespace Sample.RabbitMQ.MySql public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() - .ConfigureLogging((hostingContext, builder) => - { - hostingContext.HostingEnvironment.ConfigureNLog("nlog.config"); - }) - .UseNLog() .Build(); } } diff --git a/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj b/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj index 5c981a3..3b11738 100644 --- a/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj +++ b/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + netcoreapp2.1 @@ -10,9 +10,8 @@ - - - + + @@ -22,10 +21,5 @@ - - - PreserveNewest - - diff --git a/samples/Sample.RabbitMQ.MySql/Startup.cs b/samples/Sample.RabbitMQ.MySql/Startup.cs index 6525770..554a624 100644 --- a/samples/Sample.RabbitMQ.MySql/Startup.cs +++ b/samples/Sample.RabbitMQ.MySql/Startup.cs @@ -23,9 +23,6 @@ namespace Sample.RabbitMQ.MySql public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - loggerFactory.AddConsole(); - loggerFactory.AddDebug(); - app.UseMvc(); app.UseCap(); From 8a85a469c61d3afdfa73cc4fd0fb97075b5cbed0 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 5 Jun 2018 10:32:19 +0800 Subject: [PATCH 52/57] Add Directory.Build.props --- Directory.Build.props | 18 ++++++++++++++++++ build/common.props | 17 ----------------- .../DotNetCore.CAP.Kafka.csproj | 2 -- .../DotNetCore.CAP.MySql.csproj | 2 -- .../DotNetCore.CAP.PostgreSql.csproj | 2 -- .../DotNetCore.CAP.RabbitMQ.csproj | 2 -- .../DotNetCore.CAP.SqlServer.csproj | 2 -- 7 files changed, 18 insertions(+), 27 deletions(-) create mode 100644 Directory.Build.props delete mode 100644 build/common.props diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..c4ae862 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,18 @@ + + + + + + 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. + + + \ No newline at end of file diff --git a/build/common.props b/build/common.props deleted file mode 100644 index 80c2d79..0000000 --- a/build/common.props +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - CAP - savorboard;dotnetcore - https://github.com/dotnetcore/CAP - git - 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. - - - diff --git a/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj b/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj index 72e580e..8c8d5e7 100644 --- a/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj +++ b/src/DotNetCore.CAP.Kafka/DotNetCore.CAP.Kafka.csproj @@ -1,7 +1,5 @@  - - netstandard2.0 DotNetCore.CAP.Kafka diff --git a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj index 1e85be1..ecc6794 100644 --- a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj +++ b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj @@ -1,7 +1,5 @@  - - netstandard2.0 DotNetCore.CAP.MySql diff --git a/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj b/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj index 81b1b5c..fb40b7c 100644 --- a/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj +++ b/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj @@ -1,7 +1,5 @@  - - netstandard2.0 DotNetCore.CAP.PostgreSql diff --git a/src/DotNetCore.CAP.RabbitMQ/DotNetCore.CAP.RabbitMQ.csproj b/src/DotNetCore.CAP.RabbitMQ/DotNetCore.CAP.RabbitMQ.csproj index 6a68173..deccfb7 100644 --- a/src/DotNetCore.CAP.RabbitMQ/DotNetCore.CAP.RabbitMQ.csproj +++ b/src/DotNetCore.CAP.RabbitMQ/DotNetCore.CAP.RabbitMQ.csproj @@ -1,7 +1,5 @@  - - netstandard2.0 DotNetCore.CAP.RabbitMQ diff --git a/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj b/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj index 7d03a24..d45d0f4 100644 --- a/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj +++ b/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj @@ -1,7 +1,5 @@  - - netstandard2.0 DotNetCore.CAP.SqlServer From ff5872d4f0d9d98813017d860a46cdec394e4b89 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 5 Jun 2018 10:32:49 +0800 Subject: [PATCH 53/57] refactor csproj structure. --- CAP.sln | 1 - .../Sample.RabbitMQ.MySql.csproj | 6 ++-- src/DotNetCore.CAP/DotNetCore.CAP.csproj | 33 ++++--------------- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/CAP.sln b/CAP.sln index 828d82a..225537c 100644 --- a/CAP.sln +++ b/CAP.sln @@ -36,7 +36,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{10C0818D build.cake = build.cake build.ps1 = build.ps1 build.sh = build.sh - build\common.props = build\common.props build\index.cake = build\index.cake build\util.cake = build\util.cake build\version.cake = build\version.cake diff --git a/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj b/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj index 3b11738..cf0add9 100644 --- a/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj +++ b/samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj @@ -12,10 +12,8 @@ - - - - + + diff --git a/src/DotNetCore.CAP/DotNetCore.CAP.csproj b/src/DotNetCore.CAP/DotNetCore.CAP.csproj index 464a2a5..20df14b 100644 --- a/src/DotNetCore.CAP/DotNetCore.CAP.csproj +++ b/src/DotNetCore.CAP/DotNetCore.CAP.csproj @@ -1,32 +1,14 @@ - - + + netstandard2.0 - DotNetCore.CAP - $(PackageTags); + bin\$(Configuration)\netstandard2.0\DotNetCore.CAP.xml 1701;1702;1705;CS1591 - - - - - - - - - - - - - - - - - - + @@ -47,6 +29,7 @@ + @@ -60,6 +43,7 @@ + True @@ -143,9 +127,4 @@ Strings.Designer.cs - - - RazorGenerator - - \ No newline at end of file From 7fc1bb590803e10691d79dde7df36ad43104558a Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 5 Jun 2018 11:00:41 +0800 Subject: [PATCH 54/57] Fix compilation errors after the upgrade --- src/DotNetCore.CAP.MySql/MySqlMonitoringApi.cs | 8 ++++---- src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs | 6 +++--- src/DotNetCore.CAP.SqlServer/SqlServerMonitoringApi.cs | 8 ++++---- src/DotNetCore.CAP/Dashboard/TimelineCounter.cs | 8 ++++++++ 4 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 src/DotNetCore.CAP/Dashboard/TimelineCounter.cs diff --git a/src/DotNetCore.CAP.MySql/MySqlMonitoringApi.cs b/src/DotNetCore.CAP.MySql/MySqlMonitoringApi.cs index 6fd0888..a8a4bdf 100644 --- a/src/DotNetCore.CAP.MySql/MySqlMonitoringApi.cs +++ b/src/DotNetCore.CAP.MySql/MySqlMonitoringApi.cs @@ -126,7 +126,7 @@ select count(Id) from `{0}.received` where StatusName = N'Failed';", _prefix); { var sqlQuery = $"select count(Id) from `{_prefix}.{tableName}` where StatusName = @state"; - var count = connection.ExecuteScalar(sqlQuery, new {state = statusName}); + var count = connection.ExecuteScalar(sqlQuery, new { state = statusName }); return count; } @@ -167,10 +167,10 @@ select aggr.* from ( group by date_format(`Added`,'%Y-%m-%d-%H') ) aggr where `Key` in @keys;"; - var valuesMap = connection.Query( + var valuesMap = connection.Query( sqlQuery, - new {keys = keyMaps.Keys, statusName}) - .ToDictionary(x => (string) x.Key, x => (int) x.Count); + new { keys = keyMaps.Keys, statusName }) + .ToDictionary(x => x.Key, x => x.Count); foreach (var key in keyMaps.Keys) { diff --git a/src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs b/src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs index 8fcf9f8..2c73bff 100644 --- a/src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs +++ b/src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs @@ -128,7 +128,7 @@ select count(""Id"") from ""{0}"".""received"" where ""StatusName"" = N'Failed' var sqlQuery = $"select count(\"Id\") from \"{_options.Schema}\".\"{tableName}\" where Lower(\"StatusName\") = Lower(@state)"; - var count = connection.ExecuteScalar(sqlQuery, new {state = statusName}); + var count = connection.ExecuteScalar(sqlQuery, new { state = statusName }); return count; } @@ -170,9 +170,9 @@ with aggr as ( ) select ""Key"",""Count"" from aggr where ""Key""= Any(@keys);"; - var valuesMap = connection.Query(sqlQuery, new {keys = keyMaps.Keys.ToList(), statusName}) + var valuesMap = connection.Query(sqlQuery, new { keys = keyMaps.Keys.ToList(), statusName }) .ToList() - .ToDictionary(x => (string) x.Key, x => (int) x.Count); + .ToDictionary(x => x.Key, x => x.Count); foreach (var key in keyMaps.Keys) { diff --git a/src/DotNetCore.CAP.SqlServer/SqlServerMonitoringApi.cs b/src/DotNetCore.CAP.SqlServer/SqlServerMonitoringApi.cs index 732143e..31c4bcd 100644 --- a/src/DotNetCore.CAP.SqlServer/SqlServerMonitoringApi.cs +++ b/src/DotNetCore.CAP.SqlServer/SqlServerMonitoringApi.cs @@ -128,7 +128,7 @@ select count(Id) from [{0}].Received with (nolock) where StatusName = N'Failed'; var sqlQuery = $"select count(Id) from [{_options.Schema}].{tableName} with (nolock) where StatusName = @state"; - var count = connection.ExecuteScalar(sqlQuery, new {state = statusName}); + var count = connection.ExecuteScalar(sqlQuery, new { state = statusName }); return count; } @@ -171,10 +171,10 @@ with aggr as ( ) select [Key], [Count] from aggr with (nolock) where [Key] in @keys;"; - var valuesMap = connection.Query( + var valuesMap = connection.Query( sqlQuery, - new {keys = keyMaps.Keys, statusName}) - .ToDictionary(x => (string) x.Key, x => (int) x.Count); + new { keys = keyMaps.Keys, statusName }) + .ToDictionary(x => x.Key, x => x.Count); foreach (var key in keyMaps.Keys) { diff --git a/src/DotNetCore.CAP/Dashboard/TimelineCounter.cs b/src/DotNetCore.CAP/Dashboard/TimelineCounter.cs new file mode 100644 index 0000000..c4c1a0b --- /dev/null +++ b/src/DotNetCore.CAP/Dashboard/TimelineCounter.cs @@ -0,0 +1,8 @@ +namespace DotNetCore.CAP.Dashboard +{ + public class TimelineCounter + { + public string Key { get; set; } + public int Count { get; set; } + } +} From 15edd352a9497042d5849377892f16eede990af9 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 5 Jun 2018 11:01:38 +0800 Subject: [PATCH 55/57] Upgrade the dependent nuget package to the latest version --- .../Sample.Kafka.MySql.csproj | 2 +- .../DotNetCore.CAP.MySql.csproj | 8 ++--- .../DotNetCore.CAP.PostgreSql.csproj | 8 ++--- .../DotNetCore.CAP.SqlServer.csproj | 9 +++--- src/DotNetCore.CAP/DotNetCore.CAP.csproj | 14 ++++----- .../DotNetCore.CAP.MySql.Test.csproj | 29 +++++++++---------- .../DotNetCore.CAP.PostgreSql.Test.csproj | 11 ++++--- .../DotNetCore.CAP.SqlServer.Test.csproj | 24 +++++++-------- .../DotNetCore.CAP.Test.csproj | 14 ++++----- 9 files changed, 57 insertions(+), 62 deletions(-) diff --git a/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj b/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj index e4a70df..a657851 100644 --- a/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj +++ b/samples/Sample.Kafka.MySql/Sample.Kafka.MySql.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj index ecc6794..14734ad 100644 --- a/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj +++ b/src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj @@ -12,10 +12,10 @@ - - - - + + + + diff --git a/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj b/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj index fb40b7c..0e3698f 100644 --- a/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj +++ b/src/DotNetCore.CAP.PostgreSql/DotNetCore.CAP.PostgreSql.csproj @@ -12,10 +12,10 @@ - - - - + + + + diff --git a/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj b/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj index d45d0f4..27d3ca2 100644 --- a/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj +++ b/src/DotNetCore.CAP.SqlServer/DotNetCore.CAP.SqlServer.csproj @@ -4,6 +4,7 @@ netstandard2.0 DotNetCore.CAP.SqlServer $(PackageTags);SQL Server + @@ -12,10 +13,10 @@ - - - - + + + + diff --git a/src/DotNetCore.CAP/DotNetCore.CAP.csproj b/src/DotNetCore.CAP/DotNetCore.CAP.csproj index 20df14b..cc1a94d 100644 --- a/src/DotNetCore.CAP/DotNetCore.CAP.csproj +++ b/src/DotNetCore.CAP/DotNetCore.CAP.csproj @@ -32,16 +32,16 @@ - - - - + + + + - + - - + + 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 f96229e..8678e45 100644 --- a/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj +++ b/test/DotNetCore.CAP.MySql.Test/DotNetCore.CAP.MySql.Test.csproj @@ -1,11 +1,8 @@  - netcoreapp2.0 - true - DotNetCore.CAP.MySql.Test - DotNetCore.CAP.MySql.Test - true + netcoreapp2.1 + false @@ -14,20 +11,20 @@ - - - + + + - - + + - - - - - - + + + + + + \ No newline at end of file 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 2346ca5..335f851 100644 --- a/test/DotNetCore.CAP.PostgreSql.Test/DotNetCore.CAP.PostgreSql.Test.csproj +++ b/test/DotNetCore.CAP.PostgreSql.Test/DotNetCore.CAP.PostgreSql.Test.csproj @@ -1,15 +1,14 @@ - + - netcoreapp2.0 - + netcoreapp2.1 false - - - + + + 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 d8e70d4..9375d31 100644 --- a/test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj +++ b/test/DotNetCore.CAP.SqlServer.Test/DotNetCore.CAP.SqlServer.Test.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + netcoreapp2.1 false @@ -11,20 +11,20 @@ - - - + + + - - + + - - - - - - + + + + + + diff --git a/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj b/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj index 09e9dd9..7216569 100644 --- a/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj +++ b/test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj @@ -1,21 +1,19 @@  - netcoreapp2.0 - true - DotNetCore.CAP.Test - true + netcoreapp2.1 + false - + - - + + - + From b80bb9b33fd7d3137b3818fb1f5b317a8545ccea Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 5 Jun 2018 11:15:56 +0800 Subject: [PATCH 56/57] update ci.yml --- .travis.yml | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4d8bd00..f392fbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ -language: cpp +language: csharp sudo: required dist: trusty +solution: CAP.sln +dotnet: 2.1.0 matrix: include: @@ -10,33 +12,9 @@ matrix: - os: osx osx_image: xcode8.3 # macOS 10.12 -env: - global: - - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - - CLI_VERSION=2.0.0 - -addons: - apt: - packages: - - gettext - - libcurl4-openssl-dev - - libicu-dev - - libssl-dev - - libunwind8 - - zlib1g - -# Make sure build dependencies are installed. -before_install: - - if test "$TRAVIS_OS_NAME" == "osx"; then ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi - - export DOTNET_INSTALL_DIR="$PWD/.dotnetcli" - - export PATH="$DOTNET_INSTALL_DIR:$PATH" - -install: - - travis_retry curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 2.0 --version "$CLI_VERSION" --install-dir "$DOTNET_INSTALL_DIR" - # Run the build script script: - dotnet --info - - dotnet restore - - dotnet test test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj -f netcoreapp2.0 + - dotnet restore CAP.sln + - dotnet build CAP.sln + - dotnet test test/DotNetCore.CAP.Test/DotNetCore.CAP.Test.csproj From 6757576502f20e29d54f6e7909a3f068e95e4f6a Mon Sep 17 00:00:00 2001 From: Savorboard Date: Tue, 5 Jun 2018 11:20:59 +0800 Subject: [PATCH 57/57] update ci.yml --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f392fbd..ba8c1fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,8 @@ language: csharp sudo: required dist: trusty solution: CAP.sln -dotnet: 2.1.0 +dotnet: 2.1.300 +mono: none matrix: include: