Skip to content

Commit abf05fb

Browse files
authored
fix(IntegrationEventBus): Fix integration event causing startup to fail (#158)
1 parent 503a24f commit abf05fb

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

src/Dispatcher/Masa.Contrib.Dispatcher.IntegrationEvents/Processor/RetryByLocalQueueProcessor.cs

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace Masa.Contrib.Dispatcher.IntegrationEvents.Processor;
55

66
public class RetryByLocalQueueProcessor : ProcessorBase
77
{
8-
private readonly IServiceProvider _serviceProvider;
98
private readonly IOptionsMonitor<AppConfig>? _appConfig;
109
private readonly IOptions<DispatcherOptions> _options;
1110
private readonly ILogger<RetryByLocalQueueProcessor>? _logger;
@@ -18,7 +17,6 @@ public RetryByLocalQueueProcessor(
1817
IOptionsMonitor<AppConfig>? appConfig = null,
1918
ILogger<RetryByLocalQueueProcessor>? logger = null) : base(serviceProvider)
2019
{
21-
_serviceProvider = serviceProvider;
2220
_appConfig = appConfig;
2321
_options = options;
2422
_logger = logger;

src/Dispatcher/Masa.Contrib.Dispatcher.IntegrationEvents/Servers/DefaultHostedService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public DefaultHostedService(IServiceProvider serviceProvider, IEnumerable<IProce
1616

1717
public Task ExecuteAsync(CancellationToken stoppingToken)
1818
{
19-
if (_serviceProvider.GetService<IUnitOfWorkManager>() == null || _serviceProvider.GetService<IIntegrationEventLogService>() == null)
19+
if (_serviceProvider.GetService<IUnitOfWorkManager>() == null)
2020
return Task.CompletedTask;
2121

2222
var processorTasks = _processors.Select(processor => new InfiniteLoopProcessor(_serviceProvider, processor))

src/Dispatcher/Masa.Contrib.Dispatcher.IntegrationEvents/ServiceCollectionExtensions.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@ internal static IServiceCollection TryAddIntegrationEventBus(
6161
LocalQueueProcessor.SetLogger(services);
6262
services.AddScoped<IIntegrationEventBus, IntegrationEventBus>();
6363
action?.Invoke();
64-
services.AddSingleton<IProcessor, RetryByDataProcessor>();
65-
services.AddSingleton<IProcessor, RetryByLocalQueueProcessor>();
66-
services.AddSingleton<IProcessor, DeletePublishedExpireEventProcessor>();
67-
services.AddSingleton<IProcessor, DeleteLocalQueueExpiresProcessor>();
64+
65+
if (services.Any(d => d.ServiceType == typeof(IIntegrationEventLogService)))
66+
{
67+
services.AddSingleton<IProcessor, RetryByDataProcessor>();
68+
services.AddSingleton<IProcessor, RetryByLocalQueueProcessor>();
69+
services.AddSingleton<IProcessor, DeletePublishedExpireEventProcessor>();
70+
services.AddSingleton<IProcessor, DeleteLocalQueueExpiresProcessor>();
71+
}
6872
services.TryAddSingleton<IProcessingServer, DefaultHostedService>();
73+
6974
services.AddHostedService<IntegrationEventHostedService>();
7075
if (services.All(service => service.ServiceType != typeof(IUnitOfWork)))
7176
{

test/Masa.Contrib.Dispatcher.IntegrationEvents.Tests/IntegrationEventBusTest.cs

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// Copyright (c) MASA Stack All rights reserved.
22
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33

4-
using Masa.Contrib.Dispatcher.IntegrationEvents.Tests.Events;
5-
using Masa.Contrib.Dispatcher.IntegrationEvents.Tests.Infrastructure;
6-
using Microsoft.Extensions.DependencyInjection.Extensions;
7-
84
namespace Masa.Contrib.Dispatcher.IntegrationEvents.Tests;
95

106
[TestClass]

test/Masa.Contrib.Dispatcher.IntegrationEvents.Tests/_Imports.cs

+3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
global using Masa.BuildingBlocks.Dispatcher.IntegrationEvents.Logs;
1010
global using Masa.Contrib.Dispatcher.IntegrationEvents.Options;
1111
global using Masa.Contrib.Dispatcher.IntegrationEvents.Processor;
12+
global using Masa.Contrib.Dispatcher.IntegrationEvents.Tests.Events;
13+
global using Masa.Contrib.Dispatcher.IntegrationEvents.Tests.Infrastructure;
1214
global using Masa.Utils.Models.Config;
1315
global using Microsoft.Extensions.DependencyInjection;
16+
global using Microsoft.Extensions.DependencyInjection.Extensions;
1417
global using Microsoft.Extensions.Logging;
1518
global using Microsoft.Extensions.Logging.Abstractions;
1619
global using Microsoft.Extensions.Options;

0 commit comments

Comments
 (0)