rabbitmq 遇到几个错误,求解

qq_36028604 2017-01-04 02:00:21



我是写了一个死循环,进行接收消息,如果接收失败会重新new一个mq并且初始化connection,重新开始接收消息。

现在碰到两个问题。
一个是有时候接收消息会出现异常
Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=541, text="Unexpected Exception", classId=0, methodId=0, cause=System.IO.IOException: Unable to read data from the transport connection: 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。. ---> System.Net.Sockets.SocketException: 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at RabbitMQ.Client.Impl.Frame.ReadFrom(NetworkBinaryReader reader)
at RabbitMQ.Client.Impl.SocketFrameHandler.ReadFrame()
at RabbitMQ.Client.Framing.Impl.Connection.MainLoopIteration()
at RabbitMQ.Client.Framing.Impl.Connection.MainLoop()

之后重新创建mq时候,无法初始化connection :None of the specified endpoints were reachable

这是什么原因呢?一般过一段时间(短的话就几秒,慢的话几小时)就会重新恢复。我是用c#开发的
...全文
3498 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
这种问题首先去查文档和FAQ
qq_36028604 2017-01-04
  • 打赏
  • 举报
回复
那为什么自动重新建立一个mq的时候,CreatConnection会报 “None of the specified endpoints were reachable ”这个错误呢?
  • 打赏
  • 举报
回复
在内层加个 finally { if(mq1.queue) mq1.Close(); 先把当前出错的连接释放 } 远程主机强迫关闭了一个现有的连接,就是服务端已经关闭(一般由于出错导致连接意外终止),客户端仍尝试去读就报这错 GetMessge那样写的话就不用再加try-catch了,内层的while不太好,最好还是事件或者异步方法递归读取

           this.connection = new ConnectionFactory()
           {
                    AutomaticRecoveryEnabled = true,
                    NetworkRecoveryInterval = TimeSpan.FromSeconds(10),
                    RequestedHeartbeat = 60,
            };
            this.channel = connection.GetChannel(uri);
            channel.ConfirmSelect();
            this.channel.QueueDeclare(queue, true, false, false, null);
            this.consumer = new EventingBasicConsumer(channel);
            this.consumer.Received += Consumer_Received;
            this.channel.BasicConsume(queue, false, consumer);

//事件处理,自己反序列化一下
private void Consumer_Received(object sender, BasicDeliverEventArgs e)
        {
            var type = Type.GetType(e.BasicProperties.Type);
            var result = BinarySerializer / JsonSerializer.DeserializeObject(e.Body, type);  
        }

//往队列里发消息
var correlationId = Guid.NewGuid().ToString();
            var request = channel.CreateBasicProperties();
            request.ReplyTo = queue;
            request.CorrelationId = correlationId;   //并发控制用
            request.Type = typeof(Output).AssemblyQualifiedName;
上面就是最基本的处理的,文档里有demo的,不要用while+thread
qq_36028604 2017-01-04
  • 打赏
  • 举报
回复
有时候,接收失败是这个原因 MQ:"mq-backup.keytop.cn"监听失败,详细信息:The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=541, text="Unexpected Exception", classId=0, methodId=0, cause=System.IO.IOException: Unable to read data from the transport connection: 远程主机强迫关闭了一个现有的连接。. ---> System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接。 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at RabbitMQ.Client.Impl.Frame.ReadFrom(NetworkBinaryReader reader) at RabbitMQ.Client.Impl.SocketFrameHandler.ReadFrame() at RabbitMQ.Client.Framing.Impl.Connection.MainLoopIteration() at RabbitMQ.Client.Framing.Impl.Connection.MainLoop()

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧