Skip to content

Commit

Permalink
Improved AddDelayedSessionProcessor parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianKuesters committed Dec 1, 2023
1 parent 9ddcf34 commit 121227e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ List<PrintSessionIdCommand> GetProcessedCommandsHistory()
}

// Start the hosted service and wait a while for it to process the messages
await StartHostedServiceAsync();
var hostedService = await StartHostedServiceAsync();
while (GetProcessedCommandsHistory().Count < totalMessagesCount)
{
await Task.Delay(TimeSpan.FromSeconds(2));
}

// Stop the hosted service
await hostedService.StopAsync(CancellationToken.None);

// Assert
GetProcessedCommandsHistory()
.GetRange(0, 10)
Expand All @@ -99,7 +102,7 @@ List<PrintSessionIdCommand> GetProcessedCommandsHistory()
.HaveCount(1);
}

private async Task StartHostedServiceAsync()
private async Task<IHostedService> StartHostedServiceAsync()
{
var hostedService = _serviceProvider
.GetServices<IHostedService>()
Expand All @@ -109,5 +112,7 @@ private async Task StartHostedServiceAsync()

// wait a bit for the hosted service to start and may process deprecated messages
await Task.Delay(TimeSpan.FromSeconds(5));

return hostedService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public AzureServiceBusSetupEnvironment AddDelayedProcessor<TCommand>(
/// </summary>
public AzureServiceBusSetupEnvironment AddDelayedSessionProcessor<TCommand>(
int maxConcurrentSessions = 1,
int maxConcurrentCallsPerSession = 1,
Action<ServiceBusSessionProcessorOptions>? configureSessionProcessorOptions = null)
where TCommand : ICommandBase
{
Expand All @@ -72,6 +73,7 @@ public AzureServiceBusSetupEnvironment AddDelayedSessionProcessor<TCommand>(
var serviceBusSessionProcessorOptions = new ServiceBusSessionProcessorOptions()
{
MaxConcurrentSessions = maxConcurrentSessions,
MaxConcurrentCallsPerSession = maxConcurrentCallsPerSession,
SessionIdleTimeout = TimeSpan.FromSeconds(2)
};
Expand Down

0 comments on commit 121227e

Please sign in to comment.