fix: RabbitMQ 연결 실패 시 앱 크래시 방지 (#124) #125

Merged
seonkyu.kim merged 2 commits from fix/#124-rabbitmq-crash into develop 2026-02-10 10:16:33 +00:00
Showing only changes of commit efd6615809 - Show all commits

View File

@ -25,10 +25,19 @@ public class RabbitMQInitializer : IHostedService
public async Task StartAsync(CancellationToken cancellationToken)
{
try
{
await InitializeAsync(cancellationToken);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "RabbitMQ 초기화 실패 — 서버는 계속 실행됩니다. 메시지 발송 시 재연결을 시도합니다.");
}
}
public async Task InitializeAsync(CancellationToken cancellationToken)
{
await using var channel = await _connection.CreateChannelAsync(cancellationToken);
// Exchange 선언: Direct, Durable
await channel.ExchangeDeclareAsync(
exchange: _settings.Exchange,
type: ExchangeType.Direct,
@ -44,7 +53,6 @@ public class RabbitMQInitializer : IHostedService
{ "x-message-ttl", _settings.MessageTtl }
};
// Push Queue 선언
await channel.QueueDeclareAsync(
queue: _settings.PushQueue,
durable: true,
@ -62,7 +70,6 @@ public class RabbitMQInitializer : IHostedService
_logger.LogInformation("Queue 선언 및 바인딩 완료: {Queue} → {Exchange} (routing_key: push)",
_settings.PushQueue, _settings.Exchange);
// Schedule Queue 선언
await channel.QueueDeclareAsync(
queue: _settings.ScheduleQueue,
durable: true,
@ -80,12 +87,6 @@ public class RabbitMQInitializer : IHostedService
_logger.LogInformation("Queue 선언 및 바인딩 완료: {Queue} → {Exchange} (routing_key: schedule)",
_settings.ScheduleQueue, _settings.Exchange);
}
catch (Exception ex)
{
_logger.LogError(ex, "RabbitMQ Exchange/Queue 초기화 실패");
throw;
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}