问题重现:
使用RabbitClient时候切换网络,由wifi切换到流量模式的时候,出现如下异常。
com.rabbitmq.client.AlreadyClosedException: connection is already closed due to connection error; cause: java.net.SocketException: Software caused connection abort
at com.rabbitmq.client.impl.AMQChannel.processShutdownSignal(AMQChannel.java:283)
at com.rabbitmq.client.impl.ChannelN.startProcessShutdownSignal(ChannelN.java:267)
at com.rabbitmq.client.impl.ChannelN.close(ChannelN.java:573)
at com.rabbitmq.client.impl.ChannelN.close(ChannelN.java:509)
at com.rabbitmq.client.impl.ChannelN.close(ChannelN.java:503)
at edu.hrbeu.ice.mobilecar.activity.MapActivity$2$override.run(MapActivity.java:310)
at edu.hrbeu.ice.mobilecar.activity.MapActivity$2$override.access$dispatch(MapActivity.java)
at edu.hrbeu.ice.mobilecar.activity.MapActivity$2.run(MapActivity.java:0)
at java.lang.Thread.run(Thread.java:761)
异常定位:在重message池中取数据的时候捕获异常。
try { if (channel != null) channel.close(); if (connection != null) connection.close(); } catch (IOException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); }问题解决:
方法1:
将以上代码改为
try { if (channel != null) { channel.abort(); } if (connection != null) { connection.close(); } } catch (IOException e) { e.printStackTrace(); }catch (AlreadyClosedException e){ e.printStackTrace(); }方法2:将以上代码删除 不去捕获异常,不做操作。