Skip to content

Commit

Permalink
Remove need for RabbitMQ if the initial config has it disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankSzendzielarz committed Jan 28, 2024
1 parent b3e866c commit d9c3f4d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions SimpleAlgorandStream/Services/StatePumpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal class StatePumpService : BackgroundService
private readonly ILogger<StatePumpService> _logger;
private readonly IHostApplicationLifetime _appLifetime;
//INFO: push targets cannot be dynamically changed on configuration change
private readonly IConnection _rabbitMQConnection;
private IConnection _rabbitMQConnection;
private readonly IHubContext<AlgorandHub> _signalRHub;

private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
Expand All @@ -71,14 +71,14 @@ public StatePumpService(IOptionsMonitor<AlgodSource> algodSource,
_algodSourceMonitor.OnChange(async _ =>
{
await setupClient();
setupRabbitMQ();
});
_logger = logger;
_clientFactory = clientFactory;

var factory = new ConnectionFactory() { HostName = _pushTargetsMonitor.CurrentValue.RabbitMQ.HostName };
_rabbitMQConnection = factory.CreateConnection();

setupClient().Wait();

setupRabbitMQ();



Expand All @@ -93,7 +93,14 @@ public StatePumpService(IOptionsMonitor<AlgodSource> algodSource,

}


private void setupRabbitMQ()
{
if (_pushTargetsMonitor.CurrentValue.RabbitMQ.Enabled)
{
var factory = new ConnectionFactory() { HostName = _pushTargetsMonitor.CurrentValue.RabbitMQ.HostName };
_rabbitMQConnection = factory.CreateConnection();
}
}


private async Task setupClient()
Expand Down
2 changes: 1 addition & 1 deletion SimpleAlgorandStream/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"HostName": "localhost",
"Port": 5672,
"ExchangeName": "AlgorandFeed",
"Enabled": true
"Enabled": false
}
},
"Logging": {
Expand Down

0 comments on commit d9c3f4d

Please sign in to comment.