From 4a5da9085c26a714bc2f28bd303cff2cd9416aa5 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 8 Aug 2019 05:06:07 +0300 Subject: [PATCH 01/12] Write publish message store (#380) * made possible updating message before storing to db made updating message Content possible on WritePublishMessageStoreBefore event * added TracingHeaders to BrokerStoreEventData model --- .../Abstractions/CapPublisherBase.cs | 22 ++++++++++++++++++- .../DiagnosticListenerExtensions.cs | 19 +++------------- .../Diagnostics/EventData.Broker.Store.cs | 22 +++++++++++++++++++ 3 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 src/DotNetCore.CAP/Diagnostics/EventData.Broker.Store.cs diff --git a/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs b/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs index 90665fd..a936369 100644 --- a/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs +++ b/src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs @@ -68,7 +68,12 @@ namespace DotNetCore.CAP.Abstractions try { - operationId = s_diagnosticListener.WritePublishMessageStoreBefore(message); + var tracingResult = TracingBefore(message.Name, message.Content); + operationId = tracingResult.Item1; + + message.Content = tracingResult.Item2 != null + ? Helper.AddTracingHeaderProperty(message.Content, tracingResult.Item2) + : message.Content; if (Transaction.Value?.DbTransaction == null) { @@ -100,6 +105,21 @@ namespace DotNetCore.CAP.Abstractions throw; } } + + private (Guid, TracingHeaders) TracingBefore(string topic, string values) + { + Guid operationId = Guid.NewGuid(); + + var eventData = new BrokerStoreEventData( + operationId, + "", + topic, + values); + + s_diagnosticListener.WritePublishMessageStoreBefore(eventData); + + return (operationId, eventData.Headers); + } protected abstract Task ExecuteAsync(CapPublishedMessage message, ICapTransaction transaction = null, diff --git a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs index da0cc0c..e0b249b 100644 --- a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs +++ b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs @@ -38,26 +38,13 @@ namespace DotNetCore.CAP.Diagnostics //============================================================================ //==================== Before publish store message ==================== //============================================================================ - public static Guid WritePublishMessageStoreBefore(this DiagnosticListener @this, - CapPublishedMessage message, - [CallerMemberName] string operation = "") + public static void WritePublishMessageStoreBefore(this DiagnosticListener @this, BrokerStoreEventData eventData) { if (@this.IsEnabled(CapBeforePublishMessageStore)) { - var operationId = Guid.NewGuid(); - - @this.Write(CapBeforePublishMessageStore, new - { - OperationId = operationId, - Operation = operation, - MessageName = message.Name, - MessageContent = message.Content - }); - - return operationId; + eventData.Headers = new TracingHeaders(); + @this.Write(CapBeforePublishMessageStore, eventData); } - - return Guid.Empty; } public static void WritePublishMessageStoreAfter(this DiagnosticListener @this, diff --git a/src/DotNetCore.CAP/Diagnostics/EventData.Broker.Store.cs b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.Store.cs new file mode 100644 index 0000000..fed5f71 --- /dev/null +++ b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.Store.cs @@ -0,0 +1,22 @@ +using System; + +namespace DotNetCore.CAP.Diagnostics +{ + public class BrokerStoreEventData : EventData + { + public BrokerStoreEventData( + Guid operationId, + string operation, + string messageName, + string messageContent) : base(operationId, operation) + { + MessageName = messageName; + MessageContent = messageContent; + } + + public string MessageName { get; set; } + public string MessageContent { get; set; } + + public TracingHeaders Headers { get; set; } + } +} \ No newline at end of file From b5e8716f7854f3824357c515aae84b2342268ee1 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 9 Aug 2019 13:47:26 +0800 Subject: [PATCH 02/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e4704c..7973cf8 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,7 @@ services.AddCap(x => }); ``` -The default dashboard address is :[http://localhost:xxx/cap](http://localhost:xxx/cap) , you can also change the `cap` suffix to others with `d.MatchPath` configuration options. +The default dashboard address is :[http://localhost:xxx/cap](http://localhost:xxx/cap), you can also configure the `/cap` suffix with `x.UseDashboard(opt =>{ opt.MatchPath="/mycap"; })`. ![dashboard](http://images2017.cnblogs.com/blog/250417/201710/250417-20171004220827302-189215107.png) From d531354e4b1b364bd963e4852e2ddf93eb5a0646 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 13 Aug 2019 11:08:59 +0300 Subject: [PATCH 03/12] Diagnostic retries (#382) * added Retries number to WritePublishError diagnostic event * added Retries number to WriteSubscriberInvokeError diagnostic event --- .../Diagnostics/DiagnosticListenerExtensions.cs | 3 ++- .../Diagnostics/EventData.Broker.PublishError.cs | 4 +++- .../Diagnostics/EventData.SubscriberInvokeError.cs | 6 ++++-- src/DotNetCore.CAP/IPublishMessageSender.Base.cs | 3 ++- src/DotNetCore.CAP/ISubscribeExecutor.Default.cs | 3 ++- test/DotNetCore.CAP.Test/DiagnosticsTest.cs | 4 ++-- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs index e0b249b..d3c0f97 100644 --- a/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs +++ b/src/DotNetCore.CAP/Diagnostics/DiagnosticListenerExtensions.cs @@ -203,6 +203,7 @@ namespace DotNetCore.CAP.Diagnostics Exception ex, DateTimeOffset startTime, TimeSpan duration, + int retries, [CallerMemberName] string operation = "") { if (@this.IsEnabled(CapErrorSubscriberInvoke)) @@ -214,7 +215,7 @@ namespace DotNetCore.CAP.Diagnostics @this.Write(CapErrorSubscriberInvoke, new SubscriberInvokeErrorEventData(operationId, operation, methodName, subscribeName, - subscribeGroup, parameterValues, ex, startTime, duration)); + subscribeGroup, parameterValues, ex, startTime, duration, retries)); } } } diff --git a/src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs index ec44e3b..c6fef21 100644 --- a/src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs +++ b/src/DotNetCore.CAP/Diagnostics/EventData.Broker.PublishError.cs @@ -9,12 +9,14 @@ namespace DotNetCore.CAP.Diagnostics { public BrokerPublishErrorEventData(Guid operationId, string operation, string brokerAddress, string brokerTopicName, string brokerTopicBody, Exception exception, DateTimeOffset startTime, - TimeSpan duration) + TimeSpan duration, int retries) : base(operationId, operation, brokerAddress, brokerTopicName, brokerTopicBody, startTime, duration) { + Retries = retries; Exception = exception; } + public int Retries { get; } public Exception Exception { get; } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs b/src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs index 005f70f..6c57cc5 100644 --- a/src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs +++ b/src/DotNetCore.CAP/Diagnostics/EventData.SubscriberInvokeError.cs @@ -9,12 +9,14 @@ namespace DotNetCore.CAP.Diagnostics { public SubscriberInvokeErrorEventData(Guid operationId, string operation, string methodName, string subscribeName, string subscribeGroup, string parameterValues, Exception exception, - DateTimeOffset startTime, TimeSpan duration) : base(operationId, operation, methodName, subscribeName, - subscribeGroup, parameterValues, startTime, duration) + DateTimeOffset startTime, TimeSpan duration, int retries) : base(operationId, operation, methodName, + subscribeName, subscribeGroup, parameterValues, startTime, duration) { + Retries = retries; Exception = exception; } + public int Retries { get; } public Exception Exception { get; } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/IPublishMessageSender.Base.cs b/src/DotNetCore.CAP/IPublishMessageSender.Base.cs index 873929f..4902081 100644 --- a/src/DotNetCore.CAP/IPublishMessageSender.Base.cs +++ b/src/DotNetCore.CAP/IPublishMessageSender.Base.cs @@ -190,7 +190,8 @@ namespace DotNetCore.CAP message.Content, ex, startTime, - du); + du, + message.Retries + 1); s_diagnosticListener.WritePublishError(eventData); } diff --git a/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs b/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs index 19ecbc9..f1267e3 100644 --- a/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs +++ b/src/DotNetCore.CAP/ISubscribeExecutor.Default.cs @@ -199,7 +199,8 @@ namespace DotNetCore.CAP } catch (Exception ex) { - s_diagnosticListener.WriteSubscriberInvokeError(operationId, consumerContext, ex, startTime, stopwatch.Elapsed); + s_diagnosticListener.WriteSubscriberInvokeError(operationId, consumerContext, ex, startTime, + stopwatch.Elapsed, receivedMessage.Retries + 1); throw new SubscriberExecutionFailedException(ex.Message, ex); } diff --git a/test/DotNetCore.CAP.Test/DiagnosticsTest.cs b/test/DotNetCore.CAP.Test/DiagnosticsTest.cs index b3473a9..e33d8d9 100644 --- a/test/DotNetCore.CAP.Test/DiagnosticsTest.cs +++ b/test/DotNetCore.CAP.Test/DiagnosticsTest.cs @@ -65,7 +65,7 @@ namespace DotNetCore.CAP.Test var ex = new Exception("WritePublishErrorTest"); DiagnosticsWapper(() => { - var eventData = new BrokerPublishErrorEventData(operationId, "", "", "", "", ex, DateTimeOffset.UtcNow, default(TimeSpan)); + var eventData = new BrokerPublishErrorEventData(operationId, "", "", "", "", ex, DateTimeOffset.UtcNow, default(TimeSpan), default(int)); s_diagnosticListener.WritePublishError(eventData); }, kvp => @@ -192,7 +192,7 @@ namespace DotNetCore.CAP.Test DiagnosticsWapper(() => { s_diagnosticListener.WriteSubscriberInvokeError(operationId, FackConsumerContext(), ex, - DateTimeOffset.Now, TimeSpan.MaxValue); + DateTimeOffset.Now, TimeSpan.MaxValue, default(int)); }, kvp => { if (kvp.Key.Equals(CapDiagnosticListenerExtensions.CapErrorSubscriberInvoke)) From 034bc126cfad51ae24429b19b6559f4c87a9126c Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 16 Aug 2019 22:09:06 +0800 Subject: [PATCH 04/12] Update ISSUE_TEMPLATE --- .github/ISSUE_TEMPLATE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE index 842ffa6..6034a8f 100644 --- a/.github/ISSUE_TEMPLATE +++ b/.github/ISSUE_TEMPLATE @@ -3,7 +3,7 @@ Thank you for reporting an issue. 1. It's RECOMMENDED to submit PR for typo or tiny bug fix. 2. If this's a FEATURE request, please provide: details, pseudo codes if necessary. -3. If this's a BUG, please provide: course repetition, error log and configuration. Fill in as much of the template below as you're able. +3. If this's a BUG, please provide: course repetition, error log and configuration. 感谢您向我们反馈问题。 @@ -12,4 +12,4 @@ Thank you for reporting an issue. 3. 如果是一个新需求,请提供:详细需求描述。 4. 如果是一个 BUG,请提供:复现步骤,错误日志以及相关配置。 5. 如果可能,请使用【英文】来提交,英文 issue 会被优先处理。 ---> \ No newline at end of file +--> From b8a9584d6ba8c3bdaa718dcc0cc772c74599f449 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Mon, 26 Aug 2019 21:20:02 +0800 Subject: [PATCH 05/12] Update messaging.md --- docs/content/user-guide/zh/cap/messaging.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/user-guide/zh/cap/messaging.md b/docs/content/user-guide/zh/cap/messaging.md index 8844b05..bf5c7b8 100644 --- a/docs/content/user-guide/zh/cap/messaging.md +++ b/docs/content/user-guide/zh/cap/messaging.md @@ -32,6 +32,6 @@ CAP 接收到消息之后会将消息进行 Persistent(持久化), 有关 ## 消息数据清理 -数据库消息表中具有一个 ExpiresAt 字段表示消息的过期时间,当消息发送成功或者消费成功后,CAP会将消息状态为 Successed 的 ExpiresAt 设置为 1小时 后过期,会将消息状态为 Failed 的 ExpiresAt 设置为 15天 后过期。 +数据库消息表中具有一个 ExpiresAt 字段表示消息的过期时间,当消息发送成功或者消费成功后,CAP会将消息状态为 Successed 的 ExpiresAt 设置为 1天 后过期,会将消息状态为 Failed 的 ExpiresAt 设置为 15天 后过期。 -CAP 默认情况下会每隔一个小时将消息表的数据进行清理删除,避免数据量过多导致性能的降低。清理规则为 ExpiresAt 不为空并且小于当前时间的数据。 也就是说状态为Failed的消息(正常情况他们已经被重试了 50 次),如果你15天没有人工介入处理,同样会被清理掉。 \ No newline at end of file +CAP 默认情况下会每隔一个小时将消息表的数据进行清理删除,避免数据量过多导致性能的降低。清理规则为 ExpiresAt 不为空并且小于当前时间的数据。 也就是说状态为Failed的消息(正常情况他们已经被重试了 50 次),如果你15天没有人工介入处理,同样会被清理掉。 From 3c6b704bcb83d5ef31dbc26eae4a318d0fc3bcbc Mon Sep 17 00:00:00 2001 From: "Zhenyu,Liu" Date: Wed, 28 Aug 2019 23:12:30 +0800 Subject: [PATCH 06/12] change DashboardMiddleware to async (#390) --- .../Dashboard/CAP.DashboardMiddleware.cs | 21 ++++++++++++------- .../IDashboardAuthorizationFilter.cs | 4 +++- .../LocalRequestsOnlyAuthorizationFilter.cs | 5 ++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs b/src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs index 70d85be..6907043 100644 --- a/src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs +++ b/src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs @@ -27,12 +27,13 @@ namespace DotNetCore.CAP _routes = routes ?? throw new ArgumentNullException(nameof(routes)); } - public Task Invoke(HttpContext context) + public async Task Invoke(HttpContext context) { if (!context.Request.Path.StartsWithSegments(_options.PathMatch, out var matchedPath, out var remainingPath)) { - return _next(context); + await _next(context); + return; } // Update the path @@ -48,23 +49,27 @@ namespace DotNetCore.CAP if (findResult == null) { - return _next.Invoke(context); + await _next.Invoke(context); + return; } - if (_options.Authorization.Any(filter => !filter.Authorize(dashboardContext))) + foreach (var authorizationFilter in _options.Authorization) { + var authenticateResult = await authorizationFilter.AuthorizeAsync(dashboardContext); + if (authenticateResult) continue; + var isAuthenticated = context.User?.Identity?.IsAuthenticated; context.Response.StatusCode = isAuthenticated == true - ? (int) HttpStatusCode.Forbidden - : (int) HttpStatusCode.Unauthorized; + ? (int)HttpStatusCode.Forbidden + : (int)HttpStatusCode.Unauthorized; - return Task.CompletedTask; + return; } dashboardContext.UriMatch = findResult.Item2; - return findResult.Item1.Dispatch(dashboardContext); + await findResult.Item1.Dispatch(dashboardContext); } finally { diff --git a/src/DotNetCore.CAP/Dashboard/IDashboardAuthorizationFilter.cs b/src/DotNetCore.CAP/Dashboard/IDashboardAuthorizationFilter.cs index 0e984ba..2951b14 100644 --- a/src/DotNetCore.CAP/Dashboard/IDashboardAuthorizationFilter.cs +++ b/src/DotNetCore.CAP/Dashboard/IDashboardAuthorizationFilter.cs @@ -1,10 +1,12 @@ // 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.Threading.Tasks; + namespace DotNetCore.CAP.Dashboard { public interface IDashboardAuthorizationFilter { - bool Authorize(DashboardContext context); + Task AuthorizeAsync(DashboardContext context); } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs b/src/DotNetCore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs index dafd845..7dc6d82 100644 --- a/src/DotNetCore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs +++ b/src/DotNetCore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs @@ -1,13 +1,16 @@ // 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.Threading.Tasks; using DotNetCore.CAP.Infrastructure; namespace DotNetCore.CAP.Dashboard { public class LocalRequestsOnlyAuthorizationFilter : IDashboardAuthorizationFilter { - public bool Authorize(DashboardContext context) +#pragma warning disable 1998 + public async Task AuthorizeAsync(DashboardContext context) +#pragma warning restore 1998 { var ipAddress = context.Request.RemoteIpAddress; // if unknown, assume not local From 6d27c4a2da520d13c694ad2dc723ed830fba2da4 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 30 Aug 2019 14:26:33 +0800 Subject: [PATCH 07/12] Update rabbitmq.md --- docs/content/user-guide/zh/transports/rabbitmq.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/user-guide/zh/transports/rabbitmq.md b/docs/content/user-guide/zh/transports/rabbitmq.md index 9c08d3d..09b7c7f 100644 --- a/docs/content/user-guide/zh/transports/rabbitmq.md +++ b/docs/content/user-guide/zh/transports/rabbitmq.md @@ -14,7 +14,7 @@ Install-Package DotNetCore.CAP.RabbitMQ ``` -然后,你可以在 `Startup.cs` 的 `ConfigureServices` 方法中添加基于内存的配置项。 +然后,你可以在 `Startup.cs` 的 `ConfigureServices` 方法中添加基于 RabbitMQ 的配置项。 ```csharp @@ -65,4 +65,4 @@ services.AddCap(x => }); }); -``` \ No newline at end of file +``` From aa49eba5d7e72bb83a679cf7eec161596b2fd62f Mon Sep 17 00:00:00 2001 From: Savorboard Date: Fri, 30 Aug 2019 14:27:02 +0800 Subject: [PATCH 08/12] Update kafka.md --- docs/content/user-guide/zh/transports/kafka.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/user-guide/zh/transports/kafka.md b/docs/content/user-guide/zh/transports/kafka.md index d3bf7a4..07a5355 100644 --- a/docs/content/user-guide/zh/transports/kafka.md +++ b/docs/content/user-guide/zh/transports/kafka.md @@ -14,7 +14,7 @@ Install-Package DotNetCore.CAP.Kafka ``` -然后,你可以在 `Startup.cs` 的 `ConfigureServices` 方法中添加基于内存的配置项。 +然后,你可以在 `Startup.cs` 的 `ConfigureServices` 方法中添加基于 Kafka 的配置项。 ```csharp From 36ee097a94be6eb37acadf4afa248ad3f5889cae Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 10 Oct 2019 11:20:31 +0800 Subject: [PATCH 09/12] update version to 2.6.1 --- build/version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/version.props b/build/version.props index 0550ced..db8f129 100644 --- a/build/version.props +++ b/build/version.props @@ -2,7 +2,7 @@ 2 6 - 0 + 1 $(VersionMajor).$(VersionMinor).$(VersionPatch) From 843e99420d70eda0c0ce9f02c81c00aef74de80a Mon Sep 17 00:00:00 2001 From: Yrin Leung Date: Thu, 10 Oct 2019 11:20:56 +0800 Subject: [PATCH 10/12] =?UTF-8?q?fix=20Net=20Core=203.0=EF=BC=8CDashboard?= =?UTF-8?q?=20Can't=20Load=20Js=20And=20Css.=20(#407)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dashboard/CombinedResourceDispatcher.cs | 7 ++++--- .../Dashboard/EmbeddedResourceDispatcher.cs | 13 ++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/DotNetCore.CAP/Dashboard/CombinedResourceDispatcher.cs b/src/DotNetCore.CAP/Dashboard/CombinedResourceDispatcher.cs index 65875c4..c0d880c 100644 --- a/src/DotNetCore.CAP/Dashboard/CombinedResourceDispatcher.cs +++ b/src/DotNetCore.CAP/Dashboard/CombinedResourceDispatcher.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System.Reflection; +using System.Threading.Tasks; namespace DotNetCore.CAP.Dashboard { @@ -22,14 +23,14 @@ namespace DotNetCore.CAP.Dashboard _resourceNames = resourceNames; } - protected override void WriteResponse(DashboardResponse response) + protected override async Task WriteResponse(DashboardResponse response) { foreach (var resourceName in _resourceNames) { - WriteResource( + await WriteResource( response, _assembly, - $"{_baseNamespace}.{resourceName}"); + $"{_baseNamespace}.{resourceName}").ConfigureAwait(false); } } } diff --git a/src/DotNetCore.CAP/Dashboard/EmbeddedResourceDispatcher.cs b/src/DotNetCore.CAP/Dashboard/EmbeddedResourceDispatcher.cs index c48257c..7dc20d4 100644 --- a/src/DotNetCore.CAP/Dashboard/EmbeddedResourceDispatcher.cs +++ b/src/DotNetCore.CAP/Dashboard/EmbeddedResourceDispatcher.cs @@ -30,22 +30,21 @@ namespace DotNetCore.CAP.Dashboard } } - public Task Dispatch(DashboardContext context) + public async Task Dispatch(DashboardContext context) { context.Response.ContentType = _contentType; context.Response.SetExpire(DateTimeOffset.Now.AddYears(1)); - WriteResponse(context.Response); + await WriteResponse(context.Response).ConfigureAwait(false); - return Task.FromResult(true); } - protected virtual void WriteResponse(DashboardResponse response) + protected virtual Task WriteResponse(DashboardResponse response) { - WriteResource(response, _assembly, _resourceName); + return WriteResource(response, _assembly, _resourceName); } - protected void WriteResource(DashboardResponse response, Assembly assembly, string resourceName) + protected async Task WriteResource(DashboardResponse response, Assembly assembly, string resourceName) { using (var inputStream = assembly.GetManifestResourceStream(resourceName)) { @@ -55,7 +54,7 @@ namespace DotNetCore.CAP.Dashboard $@"Resource with name {resourceName} not found in assembly {assembly}."); } - inputStream.CopyTo(response.Body); + await inputStream.CopyToAsync(response.Body).ConfigureAwait(false); } } } From 275b5b5ed1fbdf474994f86d9a207dec3ef4f845 Mon Sep 17 00:00:00 2001 From: edelibas <5927502+edelibas@users.noreply.github.com> Date: Wed, 23 Oct 2019 04:22:43 +0300 Subject: [PATCH 11/12] Dashboard - Invalid column name 'id'. (#413) System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'id'. --- src/DotNetCore.CAP.SqlServer/IMonitoringApi.SqlServer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DotNetCore.CAP.SqlServer/IMonitoringApi.SqlServer.cs b/src/DotNetCore.CAP.SqlServer/IMonitoringApi.SqlServer.cs index d5498f2..9f1efaa 100644 --- a/src/DotNetCore.CAP.SqlServer/IMonitoringApi.SqlServer.cs +++ b/src/DotNetCore.CAP.SqlServer/IMonitoringApi.SqlServer.cs @@ -181,7 +181,7 @@ select [Key], [Count] from aggr with (nolock) where [Key] in @keys;"; var sqlQuery = $@" with aggr as ( select FORMAT(Added,'yyyy-MM-dd-HH') as [Key], - count(id) [Count] + count(Id) [Count] from [{_options.Schema}].{tableName} where StatusName = @statusName group by FORMAT(Added,'yyyy-MM-dd-HH') @@ -211,4 +211,4 @@ select [Key], [Count] from aggr with (nolock) where [Key] in @keys;"; return result; } } -} \ No newline at end of file +} From 5f690e723bd43e2c60d0ca14e95fd9400b85a281 Mon Sep 17 00:00:00 2001 From: cuibty Date: Wed, 13 Nov 2019 16:35:50 +0800 Subject: [PATCH 12/12] add index to ExpiresAt (#426) --- src/DotNetCore.CAP.MySql/IStorage.MySql.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/DotNetCore.CAP.MySql/IStorage.MySql.cs b/src/DotNetCore.CAP.MySql/IStorage.MySql.cs index 5be40b8..49040d1 100644 --- a/src/DotNetCore.CAP.MySql/IStorage.MySql.cs +++ b/src/DotNetCore.CAP.MySql/IStorage.MySql.cs @@ -70,7 +70,8 @@ CREATE TABLE IF NOT EXISTS `{prefix}.received` ( `Added` datetime NOT NULL, `ExpiresAt` datetime DEFAULT NULL, `StatusName` varchar(50) NOT NULL, - PRIMARY KEY (`Id`) + PRIMARY KEY (`Id`), + INDEX `IX_ExpiresAt`(`ExpiresAt`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `{prefix}.published` ( @@ -82,7 +83,8 @@ CREATE TABLE IF NOT EXISTS `{prefix}.published` ( `Added` datetime NOT NULL, `ExpiresAt` datetime DEFAULT NULL, `StatusName` varchar(40) NOT NULL, - PRIMARY KEY (`Id`) + PRIMARY KEY (`Id`), + INDEX `IX_ExpiresAt`(`ExpiresAt`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; "; return batchSql;