diff --git a/src/RawRabbit/ErrorHandling/DefaultStrategy.cs b/src/RawRabbit/ErrorHandling/DefaultStrategy.cs index a9f97b37..6508950c 100644 --- a/src/RawRabbit/ErrorHandling/DefaultStrategy.cs +++ b/src/RawRabbit/ErrorHandling/DefaultStrategy.cs @@ -118,7 +118,7 @@ public virtual Task ExecuteAsync(Func messageHandler, Func - { - var msg = _serializer.Deserialize(args); - var errorMsg = new HandlerExceptionMessage - { - Exception = exception, - Time = DateTime.Now, - Host = Environment.MachineName, - Message = msg, - }; - channelTask.Result.BasicPublish( - exchange: _errorExchangeCfg.ExchangeName, - routingKey: args.RoutingKey, - basicProperties: args.BasicProperties, - body: _serializer.Serialize(errorMsg) - ); - channelTask.Result.Close(); - }); + await _topologyProvider.DeclareExchangeAsync(_errorExchangeCfg); + var channel = await _channelFactory.GetChannelAsync(); + var msg = _serializer.Deserialize(args); + var errorMsg = new HandlerExceptionMessage + { + Exception = exception, + Time = DateTime.Now, + Host = Environment.MachineName, + Message = msg, + }; + channel.BasicPublish( + exchange: _errorExchangeCfg.ExchangeName, + routingKey: args.RoutingKey, + basicProperties: args.BasicProperties, + body: _serializer.Serialize(errorMsg) + ); + channel.Close(); } catch (Exception e) { _logger.LogWarning($"Unable to publish message '{args.BasicProperties.MessageId}' to default error exchange.", e); - return Task.FromResult(true); } } }