diff --git a/IRaCIS.Core.API/HostService/RecurringJobConfigurationService .cs b/IRaCIS.Core.API/HostService/RecurringJobConfigurationService .cs new file mode 100644 index 000000000..429d56a28 --- /dev/null +++ b/IRaCIS.Core.API/HostService/RecurringJobConfigurationService .cs @@ -0,0 +1,30 @@ +using IRaCIS.Core.Application.MassTransit.Consumer; +using MassTransit; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using System.Threading; +using System.Threading.Tasks; + +namespace IRaCIS.Core.API.HostService +{ + public class RecurringJobConfigurationService : + BackgroundService + { + readonly IServiceScopeFactory _scopeFactory; + + public RecurringJobConfigurationService(IServiceScopeFactory scopeFactory) + { + _scopeFactory = scopeFactory; + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + await using var scope = _scopeFactory.CreateAsyncScope(); + + var endpoint = scope.ServiceProvider.GetRequiredService(); + + await endpoint.AddOrUpdateRecurringJob(nameof(MasstransitTestConsumer), new MasstransiTestCommand(), x => x.Every(minutes: 1), + stoppingToken); + } + } +} diff --git a/IRaCIS.Core.API/_ServiceExtensions/MassTransitSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/MassTransitSetup.cs index f2a6b5730..c4ca5643d 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/MassTransitSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/MassTransitSetup.cs @@ -1,7 +1,10 @@ -using IRaCIS.Core.Application.MassTransit.Consumer; +using IRaCIS.Core.API.HostService; +using IRaCIS.Core.Application.MassTransit.Consumer; using IRaCIS.Core.Domain.BaseModel; +using IRaCIS.Core.Infra.EFCore; using MassTransit; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using System; namespace IRaCIS.Core.API @@ -41,7 +44,7 @@ namespace IRaCIS.Core.API cfg.UseConsumeFilter(typeof(ConsumeExceptionFilter<>), context, x => x.Include(type => type.IsAssignableTo(typeof(DomainEvent)))); - + cfg.UseConsumeFilter(typeof(CultureInfoFilter<>), context, x => x.Include(type => type.IsAssignableTo(typeof(DomainEvent)))); @@ -49,8 +52,67 @@ namespace IRaCIS.Core.API }); + + #region rabitmq obsolute + + //cfg.UsingRabbitMq((context, cfg) => + //{ + // cfg.UsePublishMessageScheduler(); + + // cfg.Host( + // host: "106.14.89.110", + // port: 5672, + // virtualHost: "/", + // configure: hostConfig => + // { + // hostConfig.Username("rabbitmq"); + // hostConfig.Password("rabbitmq"); + // }); + + // cfg.ConfigureEndpoints(context); + //}); + #endregion + + #region Outbox obsolute + + //cfg.AddConfigureEndpointsCallback((context, name, cfg) => + //{ + // cfg.UseEntityFrameworkOutbox(context); + + // //cfg.UseDelayedRedelivery(r => r.Intervals(TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(30))); + + // //// 全局重试策略:重试 3 次,每次延迟 5 秒 + // //cfg.UseMessageRetry(retryConfig => + // //{ + // // retryConfig.Interval(3, TimeSpan.FromSeconds(10)); + // //}); + //}); + + //cfg.AddEntityFrameworkOutbox(o => + //{ + // o.UseSqlServer(); + // o.UseBusOutbox(); + //}); + + #endregion + + }); + + + //services.AddOptions() + // .Configure(options => + // { + // options.WaitUntilStarted = true; + // options.StartTimeout = TimeSpan.FromMinutes(1); + // options.StopTimeout = TimeSpan.FromMinutes(1); + // }); + + //services.AddOptions() + // .Configure(options => options.ShutdownTimeout = TimeSpan.FromMinutes(1)); + + //services.AddHostedService(); #endregion