【发布时间】:2019-03-01 14:44:35
【问题描述】:
您好,我是公共交通和 RabbitMQ 的菜鸟。我正在尝试实现一个错误消费者,它只会从错误队列中读取,而不会实际消费并将消息从错误队列中取出。
我设置了一个消费者和一个错误消费者。
cfg.ReceiveEndpoint(host, nameof(MassMailJobCommand), e =>
{
e.Consumer<MassMailJobCommandConsumer>(context);
e.Consumer<FaultConsumer<MassMailJobCommand>>(context);
});
这是我的 FaultConsumer 类
public class FaultConsumer<T> : IConsumer<Fault<T>>
{
private INotificationsClient _notificationsClient;
private NotificationsOptions _notificationsOptions;
private ILogger _logger;
public FaultConsumer(ILogger<T> logger,
IOptionsSnapshot<NotificationsOptions> notificationsOptions,
INotificationsClient notificationClient
)
{
_notificationsClient = notificationClient;
_notificationsOptions = notificationsOptions.Value;
_logger = logger;
}
public async Task Consume(ConsumeContext<Fault<T>> context)
{
string exceptions = "";
foreach (var ex in context.Message.Exceptions)
{
exceptions += $"{ex.StackTrace.ToString()};" +
"\n=================>>>>>>>>====================>>>>>>>>==========================\n" +
"====================== *END OF STACKTRACE* =========================\n" +
"===================>>>>>>>>====================>>>>>>>>==========================\n";
}
string message = $"Rabbit MQ Error:\n*Destination Address:* {context.DestinationAddress}\n*Original Message:* {context.Message.Message}\n*Exceptions:* {exceptions}";
await _notificationsClient.Slack(message);
}
}
它将它发送到一个松弛通道。它工作得很好,除了我不希望消息离开错误队列。
非常感谢。
【问题讨论】:
标签: c# asp.net .net rabbitmq masstransit