c# - MassTransit RabbitMQ 抛出间歇性 AlreadyClosedException(连接已处理)
问题描述
尝试发布到 RabbitMQ 时,我从 MassTransit (5.5.5) 收到以下间歇性异常。
Already closed: The AMQP operation was interrupted: AMQP close-reason,
initiated by Application, code=200, text="Connection Disposed",
classId=0, methodId=0, cause=, RabbitMQ.Client.Exceptions.AlreadyClosedException
我正在使用 Autofac 注册服务。我正在努力查看可以在哪里处理连接。任何帮助,将不胜感激。谢谢!
自动注册
builder.AddMassTransit(c =>
{
c.AddConsumer<VoucherIssuedConsumer>();
c.AddBus(context => Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var host = cfg.Host(new Uri("..."), h =>
{
h.Username("...");
h.Password("...");
});
cfg.ReceiveEndpoint(host, "vouchers", e =>
{
e.UseMessageRetry(r => r.Intervals(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(9), TimeSpan.FromSeconds(21)));
e.ConfigureConsumer<VoucherIssuedConsumer>(context);
});
}));
});
出版
internal class VoucherIssuedListener
{
private readonly IBus publisher;
public VoucherIssuedListener(IBus publisher)
{
this.publisher = publisher;
}
public async Task HandleAsync()
{
var message = ...
await publisher.Publish(message); // Throwing here intermittently
}
}
解决方案
推荐阅读
- javascript - 如何使用本机反应将缓冲区转换为图像
- c# - 在 Blazor 中使用 @inject 与 [Inject] 依赖注入之间有什么根本区别吗?
- html - 如何在 Rails 的 simple_form 中引用自隐藏字段?
- javascript - 如何使用 axios api services 和 vuex 解决 Vue 依赖循环
- java - Spring MVC如何使用ajax将字符串转换为json数组
- grails - Grails:运行虚拟应用程序时出现native2ascii错误
- css - 我主页上的 Flexbox 在 IE 11 上无法正常工作
- json - 取消嵌套存储在列中的 JSON 字符串 [BigQuery]
- makefile - OpenWRT。Makefile 目标模式不包含“%”
- python - Ev3dev Python 更改 LineLeader Sensormode