首页 > 解决方案 > 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
        }    
  }

标签: c#rabbitmqmasstransit

解决方案


推荐阅读