From 64f8920f4617ff07a0e5f0f3f377a1d0fe6731a4 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Thu, 8 Sep 2022 16:28:03 +0800 Subject: [PATCH] add LINGYUN.Abp.Webhooks.Core and LINGYUN.Abp.Webhooks.EventBus --- ...INGYUN.MicroService.WebhooksManagement.sln | 14 +++ .../LINGYUN.Abp.Webhooks.Core/FodyWeavers.xml | 3 + .../LINGYUN.Abp.Webhooks.Core/FodyWeavers.xsd | 30 +++++ .../LINGYUN.Abp.Webhooks.Core.csproj | 15 +++ .../Abp/Webhooks/AbpWebhooksCoreModule.cs | 34 +++++ .../Abp/Webhooks/AbpWebhooksOptions.cs | 4 +- .../Abp/Webhooks/IWebhookDefinitionContext.cs | 0 .../Abp/Webhooks/IWebhookDefinitionManager.cs | 0 .../Webhooks/IWebhookDefinitionProvider.cs | 7 ++ .../LINGYUN/Abp/Webhooks/WebhookDefinition.cs | 10 ++ .../Abp/Webhooks/WebhookDefinitionContext.cs | 0 .../Abp/Webhooks/WebhookDefinitionManager.cs | 0 .../Abp/Webhooks/WebhookDefinitionProvider.cs | 2 +- .../LINGYUN/Abp/Webhooks/WebhookEvent.cs | 0 .../Abp/Webhooks/WebhookGroupDefinition.cs | 0 .../LINGYUN/Abp/Webhooks/WebhookHeader.cs | 9 +- .../LINGYUN/Abp/Webhooks/WebhookPayload.cs | 0 .../FodyWeavers.xml | 3 + .../FodyWeavers.xsd | 30 +++++ .../LINGYUN.Abp.Webhooks.EventBus.csproj | 19 +++ .../EventBus/AbpWebhooksEventBusModule.cs | 19 +++ .../DistributedEventBusWebhookPublisher.cs | 71 +++++++++++ .../Webhooks/EventBus/WebhooksEventData.cs | 39 ++++++ .../LINGYUN.Abp.Webhooks.csproj | 4 + .../LINGYUN/Abp/Webhooks/AbpWebhooksModule.cs | 28 +---- .../WebhookSenderJob.cs | 2 +- .../LINGYUN/Abp/Webhooks/IWebhookPublisher.cs | 2 +- .../EventBus/Handlers/WebhooksEventHandler.cs | 117 ++++++++++++++++++ ...ice.WebhooksManagement.HttpApi.Host.csproj | 1 + .../WebhooksManagementHttpApiHostModule.cs | 7 ++ ...ice.WorkflowManagement.HttpApi.Host.csproj | 12 ++ ...owManagementHttpApiHostModule.Configure.cs | 65 +++++++++- .../WorkflowManagementHttpApiHostModule.cs | 30 ++++- docker-compose.override.yml | 12 ++ docker-compose.yml | 7 ++ 35 files changed, 555 insertions(+), 41 deletions(-) create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/FodyWeavers.xml create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/FodyWeavers.xsd create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN.Abp.Webhooks.Core.csproj create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/AbpWebhooksCoreModule.cs rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/AbpWebhooksOptions.cs (82%) rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/IWebhookDefinitionContext.cs (100%) rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/IWebhookDefinitionManager.cs (100%) create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/IWebhookDefinitionProvider.cs rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/WebhookDefinition.cs (81%) rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/WebhookDefinitionContext.cs (100%) rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/WebhookDefinitionManager.cs (100%) rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/WebhookDefinitionProvider.cs (72%) rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/WebhookEvent.cs (100%) rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/WebhookGroupDefinition.cs (100%) rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/WebhookHeader.cs (71%) rename aspnet-core/modules/webhooks/{LINGYUN.Abp.Webhooks => LINGYUN.Abp.Webhooks.Core}/LINGYUN/Abp/Webhooks/WebhookPayload.cs (100%) create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/FodyWeavers.xml create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/FodyWeavers.xsd create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN.Abp.Webhooks.EventBus.csproj create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/AbpWebhooksEventBusModule.cs create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/DistributedEventBusWebhookPublisher.cs create mode 100644 aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/WebhooksEventData.cs rename aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/{BackgroundWorker => BackgroundJobs}/WebhookSenderJob.cs (95%) create mode 100644 aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/EventBus/Handlers/WebhooksEventHandler.cs diff --git a/aspnet-core/LINGYUN.MicroService.WebhooksManagement.sln b/aspnet-core/LINGYUN.MicroService.WebhooksManagement.sln index e0b951977..7ec7c4a19 100644 --- a/aspnet-core/LINGYUN.MicroService.WebhooksManagement.sln +++ b/aspnet-core/LINGYUN.MicroService.WebhooksManagement.sln @@ -35,6 +35,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Webhooks.Identi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Webhooks.Saas", "modules\webhooks\LINGYUN.Abp.Webhooks.Saas\LINGYUN.Abp.Webhooks.Saas.csproj", "{D7F2B64C-02F2-4097-80C1-DC41CE8FEE38}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Webhooks.EventBus", "modules\webhooks\LINGYUN.Abp.Webhooks.EventBus\LINGYUN.Abp.Webhooks.EventBus.csproj", "{46C08EF3-4C81-411E-B5E4-AC3A5040DC67}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Webhooks.Core", "modules\webhooks\LINGYUN.Abp.Webhooks.Core\LINGYUN.Abp.Webhooks.Core.csproj", "{BBF1C93D-EF73-4B00-919F-5E7F360BDB03}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -93,6 +97,14 @@ Global {D7F2B64C-02F2-4097-80C1-DC41CE8FEE38}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7F2B64C-02F2-4097-80C1-DC41CE8FEE38}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7F2B64C-02F2-4097-80C1-DC41CE8FEE38}.Release|Any CPU.Build.0 = Release|Any CPU + {46C08EF3-4C81-411E-B5E4-AC3A5040DC67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46C08EF3-4C81-411E-B5E4-AC3A5040DC67}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46C08EF3-4C81-411E-B5E4-AC3A5040DC67}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46C08EF3-4C81-411E-B5E4-AC3A5040DC67}.Release|Any CPU.Build.0 = Release|Any CPU + {BBF1C93D-EF73-4B00-919F-5E7F360BDB03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BBF1C93D-EF73-4B00-919F-5E7F360BDB03}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BBF1C93D-EF73-4B00-919F-5E7F360BDB03}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BBF1C93D-EF73-4B00-919F-5E7F360BDB03}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -111,6 +123,8 @@ Global {F4966BE6-CC96-4C23-9363-3BE4103F02E8} = {FB7A9794-06D2-42CF-939E-4626497B97BD} {93BB030A-EA01-4F08-BD41-0800D838162C} = {FB7A9794-06D2-42CF-939E-4626497B97BD} {D7F2B64C-02F2-4097-80C1-DC41CE8FEE38} = {FB7A9794-06D2-42CF-939E-4626497B97BD} + {46C08EF3-4C81-411E-B5E4-AC3A5040DC67} = {FB7A9794-06D2-42CF-939E-4626497B97BD} + {BBF1C93D-EF73-4B00-919F-5E7F360BDB03} = {FB7A9794-06D2-42CF-939E-4626497B97BD} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {80ED12A5-C899-459F-A181-ADCC9D680DE5} diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/FodyWeavers.xml b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/FodyWeavers.xml new file mode 100644 index 000000000..17d32672d --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/FodyWeavers.xsd b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/FodyWeavers.xsd new file mode 100644 index 000000000..11da52550 --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN.Abp.Webhooks.Core.csproj b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN.Abp.Webhooks.Core.csproj new file mode 100644 index 000000000..5c9a04532 --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN.Abp.Webhooks.Core.csproj @@ -0,0 +1,15 @@ + + + + + + + netstandard2.0 + + + + + + + + diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/AbpWebhooksCoreModule.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/AbpWebhooksCoreModule.cs new file mode 100644 index 000000000..2a39dfee7 --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/AbpWebhooksCoreModule.cs @@ -0,0 +1,34 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using Volo.Abp.Features; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.Webhooks; + +[DependsOn(typeof(AbpFeaturesModule))] +public class AbpWebhooksCoreModule : AbpModule +{ + public override void PreConfigureServices(ServiceConfigurationContext context) + { + AutoAddDefinitionProviders(context.Services); + } + + private static void AutoAddDefinitionProviders(IServiceCollection services) + { + var definitionProviders = new List(); + + services.OnRegistred(context => + { + if (typeof(IWebhookDefinitionProvider).IsAssignableFrom(context.ImplementationType)) + { + definitionProviders.Add(context.ImplementationType); + } + }); + + services.Configure(options => + { + options.DefinitionProviders.AddIfNotContains(definitionProviders); + }); + } +} diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/AbpWebhooksOptions.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/AbpWebhooksOptions.cs similarity index 82% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/AbpWebhooksOptions.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/AbpWebhooksOptions.cs index 072a76bcc..971ecf571 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/AbpWebhooksOptions.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/AbpWebhooksOptions.cs @@ -22,7 +22,7 @@ public class AbpWebhooksOptions /// public int MaxConsecutiveFailCountBeforeDeactivateSubscription { get; set; } - public ITypeList DefinitionProviders { get; } + public ITypeList DefinitionProviders { get; } public AbpWebhooksOptions() { @@ -30,6 +30,6 @@ public class AbpWebhooksOptions MaxSendAttemptCount = 5; MaxConsecutiveFailCountBeforeDeactivateSubscription = MaxSendAttemptCount * 3; - DefinitionProviders = new TypeList(); + DefinitionProviders = new TypeList(); } } diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/IWebhookDefinitionContext.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/IWebhookDefinitionContext.cs similarity index 100% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/IWebhookDefinitionContext.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/IWebhookDefinitionContext.cs diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/IWebhookDefinitionManager.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/IWebhookDefinitionManager.cs similarity index 100% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/IWebhookDefinitionManager.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/IWebhookDefinitionManager.cs diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/IWebhookDefinitionProvider.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/IWebhookDefinitionProvider.cs new file mode 100644 index 000000000..9e0ee161b --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/IWebhookDefinitionProvider.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.Webhooks +{ + public interface IWebhookDefinitionProvider + { + void Define(IWebhookDefinitionContext context); + } +} diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinition.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinition.cs similarity index 81% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinition.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinition.cs index 88f3a074d..9c82db155 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinition.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinition.cs @@ -25,6 +25,8 @@ namespace LINGYUN.Abp.Webhooks public List RequiredFeatures { get; set; } + public Dictionary Properties { get; } + public WebhookDefinition(string name, ILocalizableString displayName = null, ILocalizableString description = null) { if (name.IsNullOrWhiteSpace()) @@ -37,6 +39,7 @@ namespace LINGYUN.Abp.Webhooks Description = description; RequiredFeatures = new List(); + Properties = new Dictionary(); } public WebhookDefinition WithFeature(params string[] features) @@ -49,6 +52,13 @@ namespace LINGYUN.Abp.Webhooks return this; } + public WebhookDefinition WithProperty(string key, object value) + { + Properties[key] = value; + return this; + } + + public override string ToString() { return $"[{nameof(WebhookDefinition)} {Name}]"; diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinitionContext.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinitionContext.cs similarity index 100% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinitionContext.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinitionContext.cs diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinitionManager.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinitionManager.cs similarity index 100% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinitionManager.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinitionManager.cs diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinitionProvider.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinitionProvider.cs similarity index 72% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinitionProvider.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinitionProvider.cs index ead9ab679..28b520405 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookDefinitionProvider.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinitionProvider.cs @@ -2,7 +2,7 @@ namespace LINGYUN.Abp.Webhooks { - public abstract class WebhookDefinitionProvider : ITransientDependency + public abstract class WebhookDefinitionProvider : IWebhookDefinitionProvider, ITransientDependency { /// /// Used to add/manipulate webhook definitions. diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookEvent.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookEvent.cs similarity index 100% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookEvent.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookEvent.cs diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookGroupDefinition.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookGroupDefinition.cs similarity index 100% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookGroupDefinition.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookGroupDefinition.cs diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookHeader.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookHeader.cs similarity index 71% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookHeader.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookHeader.cs index 91442552f..8ec3dae22 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookHeader.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookHeader.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace LINGYUN.Abp.Webhooks { + [Serializable] public class WebhookHeader { /// @@ -14,5 +16,10 @@ namespace LINGYUN.Abp.Webhooks /// That headers will be sent with the webhook. /// public IDictionary Headers { get; set; } + + public WebhookHeader() + { + Headers = new Dictionary(); + } } } \ No newline at end of file diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookPayload.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookPayload.cs similarity index 100% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookPayload.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookPayload.cs diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/FodyWeavers.xml b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/FodyWeavers.xml new file mode 100644 index 000000000..17d32672d --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/FodyWeavers.xsd b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/FodyWeavers.xsd new file mode 100644 index 000000000..11da52550 --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN.Abp.Webhooks.EventBus.csproj b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN.Abp.Webhooks.EventBus.csproj new file mode 100644 index 000000000..88b934982 --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN.Abp.Webhooks.EventBus.csproj @@ -0,0 +1,19 @@ + + + + + + + netstandard2.0 + + + + + + + + + + + + diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/AbpWebhooksEventBusModule.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/AbpWebhooksEventBusModule.cs new file mode 100644 index 000000000..cdc1f9b31 --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/AbpWebhooksEventBusModule.cs @@ -0,0 +1,19 @@ +using Volo.Abp.EventBus; +using Volo.Abp.Json.SystemTextJson; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.Webhooks.EventBus; + +[DependsOn( + typeof(AbpWebhooksModule), + typeof(AbpEventBusModule))] +public class AbpWebhooksEventBusModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.UnsupportedTypes.TryAdd(); + }); + } +} \ No newline at end of file diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/DistributedEventBusWebhookPublisher.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/DistributedEventBusWebhookPublisher.cs new file mode 100644 index 000000000..7f20e49dc --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/DistributedEventBusWebhookPublisher.cs @@ -0,0 +1,71 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.EventBus.Distributed; + +namespace LINGYUN.Abp.Webhooks.EventBus; + +[Dependency(ReplaceServices = true)] +public class DistributedEventBusWebhookPublisher : IWebhookPublisher, ITransientDependency +{ + protected IDistributedEventBus EventBus { get; } + + public DistributedEventBusWebhookPublisher(IDistributedEventBus eventBus) + { + EventBus = eventBus; + } + + public async virtual Task PublishAsync( + string webhookName, + object data, + bool sendExactSameData = false, + WebhookHeader headers = null) + { + var eventData = new WebhooksEventData( + webhookName, + data, + sendExactSameData, + headers); + + await PublishAsync(eventData); + } + + public async virtual Task PublishAsync( + string webhookName, + object data, + Guid? tenantId, + bool sendExactSameData = false, + WebhookHeader headers = null) + { + var eventData = new WebhooksEventData( + webhookName, + data, + sendExactSameData, + headers, + new Guid?[] { tenantId }); + + await PublishAsync(eventData); + } + + public async virtual Task PublishAsync( + Guid?[] tenantIds, + string webhookName, + object data, + bool sendExactSameData = false, + WebhookHeader headers = null) + { + var eventData = new WebhooksEventData( + webhookName, + data, + sendExactSameData, + headers, + tenantIds); + + await PublishAsync(eventData); + } + + protected async virtual Task PublishAsync(WebhooksEventData eventData) + { + await EventBus.PublishAsync(eventData); + } +} diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/WebhooksEventData.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/WebhooksEventData.cs new file mode 100644 index 000000000..aecb52f31 --- /dev/null +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.EventBus/LINGYUN/Abp/Webhooks/EventBus/WebhooksEventData.cs @@ -0,0 +1,39 @@ +using System; +using Volo.Abp.EventBus; + +namespace LINGYUN.Abp.Webhooks.EventBus; + +[Serializable] +[EventName("abp.webhooks.events")] +public class WebhooksEventData +{ + public Guid?[] TenantIds { get; set; } + + public string WebhookName { get; set; } + + public object Data { get; set; } + + public bool SendExactSameData { get; set; } + + public WebhookHeader Headers { get; set; } + + public WebhooksEventData() + { + Headers = new WebhookHeader(); + TenantIds = new Guid?[0]; + } + + public WebhooksEventData( + string webhookName, + object data, + bool sendExactSameData = false, + WebhookHeader headers = null, + Guid?[] tenantIds = null) + { + WebhookName = webhookName; + Data = data; + SendExactSameData = sendExactSameData; + Headers = headers ?? new WebhookHeader(); + TenantIds = tenantIds ?? new Guid?[0]; + } +} diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN.Abp.Webhooks.csproj b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN.Abp.Webhooks.csproj index ca6031c7a..5a53bbb1f 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN.Abp.Webhooks.csproj +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN.Abp.Webhooks.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/AbpWebhooksModule.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/AbpWebhooksModule.cs index 0e66d8f81..32d1cb477 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/AbpWebhooksModule.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/AbpWebhooksModule.cs @@ -1,27 +1,19 @@ using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; using Volo.Abp.BackgroundJobs; -using Volo.Abp.Features; using Volo.Abp.Guids; using Volo.Abp.Http.Client; using Volo.Abp.Modularity; namespace LINGYUN.Abp.Webhooks; +[DependsOn(typeof(AbpWebhooksCoreModule))] [DependsOn(typeof(AbpBackgroundJobsAbstractionsModule))] -[DependsOn(typeof(AbpFeaturesModule))] [DependsOn(typeof(AbpGuidsModule))] [DependsOn(typeof(AbpHttpClientModule))] public class AbpWebhooksModule : AbpModule { internal const string WebhooksClient = "__Abp_Webhooks_HttpClient"; - public override void PreConfigureServices(ServiceConfigurationContext context) - { - AutoAddDefinitionProviders(context.Services); - } - public override void ConfigureServices(ServiceConfigurationContext context) { var options = context.Services.ExecutePreConfiguredActions(); @@ -31,22 +23,4 @@ public class AbpWebhooksModule : AbpModule client.Timeout = options.TimeoutDuration; }); } - - private static void AutoAddDefinitionProviders(IServiceCollection services) - { - var definitionProviders = new List(); - - services.OnRegistred(context => - { - if (typeof(WebhookDefinitionProvider).IsAssignableFrom(context.ImplementationType)) - { - definitionProviders.Add(context.ImplementationType); - } - }); - - services.Configure(options => - { - options.DefinitionProviders.AddIfNotContains(definitionProviders); - }); - } } diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/BackgroundWorker/WebhookSenderJob.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/BackgroundJobs/WebhookSenderJob.cs similarity index 95% rename from aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/BackgroundWorker/WebhookSenderJob.cs rename to aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/BackgroundJobs/WebhookSenderJob.cs index 4d18cb209..c648d890f 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/BackgroundWorker/WebhookSenderJob.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/BackgroundJobs/WebhookSenderJob.cs @@ -6,7 +6,7 @@ using Volo.Abp.BackgroundJobs; using Volo.Abp.DependencyInjection; using Volo.Abp.Uow; -namespace LINGYUN.Abp.Webhooks.BackgroundWorker +namespace LINGYUN.Abp.Webhooks.BackgroundJobs { public class WebhookSenderJob : AsyncBackgroundJob, ITransientDependency { diff --git a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/IWebhookPublisher.cs b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/IWebhookPublisher.cs index 3b53fec83..09962844e 100644 --- a/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/IWebhookPublisher.cs +++ b/aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/IWebhookPublisher.cs @@ -6,7 +6,7 @@ namespace LINGYUN.Abp.Webhooks public interface IWebhookPublisher { /// - /// Sends webhooks to current tenant subscriptions (). with given data, (Checks permissions) + /// Sends webhooks to current tenant subscriptions (). with given data, (Checks permissions) /// /// /// data to send diff --git a/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/EventBus/Handlers/WebhooksEventHandler.cs b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/EventBus/Handlers/WebhooksEventHandler.cs new file mode 100644 index 000000000..e546ac2f2 --- /dev/null +++ b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/EventBus/Handlers/WebhooksEventHandler.cs @@ -0,0 +1,117 @@ +using LINGYUN.Abp.Webhooks; +using LINGYUN.Abp.Webhooks.EventBus; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.BackgroundJobs; +using Volo.Abp.DependencyInjection; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.MultiTenancy; + +namespace LY.MicroService.WebhooksManagement.EventBus.Handlers; + +public class WebhooksEventHandler : + IDistributedEventHandler, + ITransientDependency +{ + public IWebhookEventStore WebhookEventStore { get; set; } + + private readonly ICurrentTenant _currentTenant; + private readonly IBackgroundJobManager _backgroundJobManager; + private readonly IWebhookSubscriptionManager _webhookSubscriptionManager; + + public WebhooksEventHandler( + IWebhookSubscriptionManager webhookSubscriptionManager, + ICurrentTenant currentTenant, + IBackgroundJobManager backgroundJobManager) + { + _currentTenant = currentTenant; + _backgroundJobManager = backgroundJobManager; + _webhookSubscriptionManager = webhookSubscriptionManager; + + WebhookEventStore = NullWebhookEventStore.Instance; + } + + public async virtual Task HandleEventAsync(WebhooksEventData eventData) + { + var subscriptions = await _webhookSubscriptionManager + .GetAllSubscriptionsOfTenantsIfFeaturesGrantedAsync( + eventData.TenantIds, + eventData.WebhookName); + + await PublishAsync(eventData.WebhookName, eventData.Data, subscriptions, eventData.SendExactSameData, eventData.Headers); + } + + protected async virtual Task PublishAsync( + string webhookName, + object data, + List webhookSubscriptions, + bool sendExactSameData = false, + WebhookHeader headers = null) + { + if (webhookSubscriptions.IsNullOrEmpty()) + { + return; + } + + var subscriptionsGroupedByTenant = webhookSubscriptions.GroupBy(x => x.TenantId); + + foreach (var subscriptionGroupedByTenant in subscriptionsGroupedByTenant) + { + var webhookInfo = await SaveAndGetWebhookAsync(subscriptionGroupedByTenant.Key, webhookName, data); + + foreach (var webhookSubscription in subscriptionGroupedByTenant) + { + var headersToSend = webhookSubscription.Headers; + if (headers != null) + { + if (headers.UseOnlyGivenHeaders)//do not use the headers defined in subscription + { + headersToSend = headers.Headers; + } + else + { + //use the headers defined in subscription. If additional headers has same header, use additional headers value. + foreach (var additionalHeader in headers.Headers) + { + headersToSend[additionalHeader.Key] = additionalHeader.Value; + } + } + } + + await _backgroundJobManager.EnqueueAsync(new WebhookSenderArgs + { + TenantId = webhookSubscription.TenantId, + WebhookEventId = webhookInfo.Id, + Data = webhookInfo.Data, + WebhookName = webhookInfo.WebhookName, + WebhookSubscriptionId = webhookSubscription.Id, + Headers = headersToSend, + Secret = webhookSubscription.Secret, + WebhookUri = webhookSubscription.WebhookUri, + SendExactSameData = sendExactSameData + }); + } + } + } + + protected async virtual Task SaveAndGetWebhookAsync( + Guid? tenantId, + string webhookName, + object data) + { + var webhookInfo = new WebhookEvent + { + WebhookName = webhookName, + Data = JsonConvert.SerializeObject(data), + TenantId = tenantId + }; + + var webhookId = await WebhookEventStore.InsertAndGetIdAsync(webhookInfo); + webhookInfo.Id = webhookId; + + return webhookInfo; + } +} diff --git a/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/LY.MicroService.WebhooksManagement.HttpApi.Host.csproj b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/LY.MicroService.WebhooksManagement.HttpApi.Host.csproj index eb3400947..a0c769763 100644 --- a/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/LY.MicroService.WebhooksManagement.HttpApi.Host.csproj +++ b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/LY.MicroService.WebhooksManagement.HttpApi.Host.csproj @@ -47,6 +47,7 @@ + diff --git a/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/WebhooksManagementHttpApiHostModule.cs b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/WebhooksManagementHttpApiHostModule.cs index 70965de33..2ead903e0 100644 --- a/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/WebhooksManagementHttpApiHostModule.cs +++ b/aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/WebhooksManagementHttpApiHostModule.cs @@ -37,6 +37,9 @@ using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.Swashbuckle; using LINGYUN.Abp.Http.Client.Wrapper; using LINGYUN.Abp.Dapr.Client.Wrapper; +using Microsoft.Extensions.DependencyInjection.Extensions; +using LINGYUN.Abp.Webhooks; +using LINGYUN.Abp.Webhooks.EventBus; namespace LY.MicroService.WebhooksManagement; @@ -50,6 +53,7 @@ namespace LY.MicroService.WebhooksManagement; typeof(WebhooksManagementEntityFrameworkCoreModule), typeof(AbpWebhooksIdentityModule), typeof(AbpWebhooksSaasModule), + typeof(AbpWebhooksEventBusModule), typeof(AbpBackgroundTasksQuartzModule), typeof(AbpBackgroundTasksDistributedLockingModule), typeof(AbpBackgroundTasksExceptionHandlingModule), @@ -107,6 +111,9 @@ public partial class WebhooksManagementHttpApiHostModule : AbpModule ConfigureDistributedLock(context.Services, configuration); ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment()); ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); + + // 分布式事件发布者不在这个项目使用, 强制替换 + context.Services.Replace(ServiceDescriptor.Transient()); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/LY.MicroService.WorkflowManagement.HttpApi.Host.csproj b/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/LY.MicroService.WorkflowManagement.HttpApi.Host.csproj index cc06f4852..35ef0c1c9 100644 --- a/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/LY.MicroService.WorkflowManagement.HttpApi.Host.csproj +++ b/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/LY.MicroService.WorkflowManagement.HttpApi.Host.csproj @@ -7,6 +7,10 @@ + + + + @@ -22,6 +26,7 @@ + @@ -44,6 +49,8 @@ + + @@ -59,6 +66,11 @@ + + + + + diff --git a/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.Configure.cs b/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.Configure.cs index 858243af4..97767076b 100644 --- a/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.Configure.cs +++ b/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.Configure.cs @@ -1,6 +1,8 @@ -using Elsa; +using DotNetCore.CAP; +using Elsa; using Elsa.Options; using Elsa.Rebus.RabbitMq; +using LINGYUN.Abp.BackgroundTasks; using LINGYUN.Abp.BlobStoring.OssManagement; using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling.Emailing; @@ -18,8 +20,10 @@ using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; +using Quartz; using StackExchange.Redis; using System; +using System.Collections.Generic; using System.Linq; using System.Text.Encodings.Web; using System.Text.Unicode; @@ -34,6 +38,7 @@ using Volo.Abp.Json; using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.MultiTenancy; +using Volo.Abp.Quartz; using Volo.Abp.Threading; using Volo.Abp.VirtualFileSystem; @@ -42,7 +47,7 @@ namespace LY.MicroService.WorkflowManagement; public partial class WorkflowManagementHttpApiHostModule { private const string DefaultCorsPolicyName = "Default"; - private const string ApplicationName = "WorkflowManagement"; + private const string ApplicationName = "Workflow"; private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); private void PreConfigureFeature() @@ -58,6 +63,60 @@ public partial class WorkflowManagementHttpApiHostModule AbpSerilogEnrichersConsts.ApplicationName = ApplicationName; } + + private void PreConfigureCAP(IConfiguration configuration) + { + PreConfigure(options => + { + options + .UseMySql(mySqlOptions => + { + configuration.GetSection("CAP:MySql").Bind(mySqlOptions); + }) + .UseRabbitMQ(rabbitMQOptions => + { + configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); + }) + .UseDashboard(); + }); + } + + private void PreConfigureQuartz(IConfiguration configuration) + { + PreConfigure(options => + { + // 如果使用持久化存储, 则配置quartz持久层 + if (configuration.GetSection("Quartz:UsePersistentStore").Get()) + { + var settings = configuration.GetSection("Quartz:Properties").Get>(); + if (settings != null) + { + foreach (var setting in settings) + { + options.Properties[setting.Key] = setting.Value; + } + } + + options.Configurator += (config) => + { + config.UsePersistentStore(store => + { + store.UseProperties = false; + store.UseJsonSerializer(); + }); + }; + } + }); + } + + private void ConfigureBackgroundTasks() + { + Configure(options => + { + options.NodeName = ApplicationName; + }); + } + private void PreConfigureElsa(IServiceCollection services, IConfiguration configuration) { var elsaSection = configuration.GetSection("Elsa"); @@ -255,7 +314,7 @@ public partial class WorkflowManagementHttpApiHostModule services.AddSwaggerGen( options => { - options.SwaggerDoc("v1", new OpenApiInfo { Title = "WorkflowManagement API", Version = "v1" }); + options.SwaggerDoc("v1", new OpenApiInfo { Title = "Workflow API", Version = "v1" }); options.DocInclusionPredicate((docName, description) => true); options.CustomSchemaIds(type => type.FullName); options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme diff --git a/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.cs b/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.cs index ad09e785c..2da1d0e44 100644 --- a/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.cs +++ b/aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.cs @@ -1,11 +1,17 @@ -using Elsa; +using DotNetCore.CAP; +using Elsa; using LINGYUN.Abp.AspNetCore.Mvc.Localization; using LINGYUN.Abp.AspNetCore.Mvc.Wrapper; using LINGYUN.Abp.AuditLogging.Elasticsearch; +using LINGYUN.Abp.Authorization.OrganizationUnits; +using LINGYUN.Abp.BackgroundTasks.DistributedLocking; +using LINGYUN.Abp.BackgroundTasks.ExceptionHandling; +using LINGYUN.Abp.BackgroundTasks.Quartz; using LINGYUN.Abp.BlobStoring.OssManagement; using LINGYUN.Abp.Data.DbMigrator; using LINGYUN.Abp.Elsa; using LINGYUN.Abp.Elsa.Activities; +using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.ExceptionHandling.Emailing; using LINGYUN.Abp.Http.Client.Wrapper; using LINGYUN.Abp.Localization.CultureMap; @@ -13,6 +19,7 @@ using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore; using LINGYUN.Abp.Saas.EntityFrameworkCore; using LINGYUN.Abp.Serilog.Enrichers.Application; using LINGYUN.Abp.Serilog.Enrichers.UniqueId; +using LINGYUN.Abp.TaskManagement.EntityFrameworkCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; @@ -31,6 +38,7 @@ using Volo.Abp.Modularity; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.Swashbuckle; +using Volo.Abp.TextTemplating.Scriban; namespace LY.MicroService.WorkflowManagement; @@ -43,21 +51,28 @@ namespace LY.MicroService.WorkflowManagement; typeof(AbpElsaModule), typeof(AbpElsaServerModule), typeof(AbpElsaActivitiesModule), - typeof(AbpEntityFrameworkCoreMySQLModule), - typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(AbpEmailingExceptionHandlingModule), typeof(AbpHttpClientIdentityModelWebModule), typeof(AbpAspNetCoreMultiTenancyModule), typeof(AbpAspNetCoreMvcLocalizationModule), + typeof(AbpBackgroundTasksQuartzModule), + typeof(AbpBackgroundTasksDistributedLockingModule), + typeof(AbpBackgroundTasksExceptionHandlingModule), + typeof(TaskManagementEntityFrameworkCoreModule), typeof(AbpFeatureManagementEntityFrameworkCoreModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(AbpSaasEntityFrameworkCoreModule), typeof(AbpLocalizationManagementEntityFrameworkCoreModule), + typeof(AbpEntityFrameworkCoreMySQLModule), + typeof(AbpAuthorizationOrganizationUnitsModule), + typeof(AbpAspNetCoreAuthenticationJwtBearerModule), + typeof(AbpTextTemplatingScribanModule), typeof(AbpDataDbMigratorModule), typeof(AbpCachingStackExchangeRedisModule), typeof(AbpAspNetCoreMvcModule), typeof(AbpSwashbuckleModule), + typeof(AbpCAPEventBusModule), typeof(AbpLocalizationCultureMapModule), typeof(AbpHttpClientWrapperModule), typeof(AbpAspNetCoreMvcWrapperModule), @@ -71,6 +86,8 @@ public partial class WorkflowManagementHttpApiHostModule : AbpModule PreConfigureApp(); PreConfigureFeature(); + PreConfigureCAP(configuration); + PreConfigureQuartz(configuration); PreConfigureElsa(context.Services, configuration); } @@ -83,6 +100,7 @@ public partial class WorkflowManagementHttpApiHostModule : AbpModule ConfigureEndpoints(); ConfigureLocalization(); ConfigureJsonSerializer(); + ConfigureBackgroundTasks(); ConfigureExceptionHandling(); ConfigureVirtualFileSystem(); ConfigureCaching(configuration); @@ -103,16 +121,18 @@ public partial class WorkflowManagementHttpApiHostModule : AbpModule var app = context.GetApplicationBuilder(); var env = context.GetEnvironment(); - app.UseStaticFiles(); + // 本地化 + app.UseMapRequestLocalization(); app.UseCorrelationId(); + app.UseStaticFiles(); app.UseRouting(); app.UseCors(DefaultCorsPolicyName); app.UseElsaFeatures(); app.UseAuthentication(); app.UseJwtTokenMiddleware(); app.UseMultiTenancy(); - app.UseAbpRequestLocalization(); app.UseAuthorization(); + app.UseCapDashboard(); app.UseSwagger(); app.UseAbpSwaggerUI(options => { diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 831ce29b5..7f8f4b216 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -96,6 +96,18 @@ services: networks: - framework + workflow-api: + build: + context: ./aspnet-core/services/Publish/workflow + volumes: + - /var/opt/abp/logs/workflow:/app/Logs + - /var/opt/abp/data/workflow/Modules:/app/Modules + depends_on: + - sts-server + restart: always + networks: + - framework + internal-apigateway: build: context: ./aspnet-core/services/Publish/internal-apigateway diff --git a/docker-compose.yml b/docker-compose.yml index b8d1a4dbf..b4b63bbb8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -50,6 +50,13 @@ services: ports: - "30045:80" + workflow-api: + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + ports: + - "30050:80" + sts-server: environment: - ASPNETCORE_ENVIRONMENT=Production