|
19 | 19 | import java.io.IOException; |
20 | 20 |
|
21 | 21 | import com.rabbitmq.client.AMQP; |
| 22 | +import com.rabbitmq.client.AlreadyClosedException; |
22 | 23 | import com.rabbitmq.client.Channel; |
23 | 24 | import com.rabbitmq.client.Connection; |
24 | 25 | import com.rabbitmq.client.Consumer; |
@@ -55,23 +56,27 @@ public void handleConsumerException(Channel channel, Throwable exception, |
55 | 56 | + " for channel " + channel); |
56 | 57 | } |
57 | 58 |
|
58 | | - protected void handleChannelKiller(Channel channel, |
59 | | - Throwable exception, |
60 | | - String what) |
61 | | - { |
62 | | - // TODO: Convert to logging framework |
63 | | - System.err.println(what + " threw an exception for channel " + |
64 | | - channel + ":"); |
| 59 | + protected void handleChannelKiller(Channel channel, Throwable exception, String what) { |
| 60 | + // TODO: log the exception |
| 61 | + System.err.println(what + " threw an exception for channel " + channel + ":"); |
65 | 62 | exception.printStackTrace(); |
66 | 63 | try { |
67 | | - ((AMQConnection) channel.getConnection()).close(AMQP.INTERNAL_ERROR, |
68 | | - "Internal error in " + what, |
69 | | - false, |
70 | | - exception); |
| 64 | + channel.close(); |
| 65 | + } catch (AlreadyClosedException ace) { |
| 66 | + //noop |
71 | 67 | } catch (IOException ioe) { |
72 | | - // Man, this clearly isn't our day. |
73 | | - // Ignore the exception? TODO: Log the nested failure |
| 68 | + // TODO: log the failure |
| 69 | + System.err.println("Failure during close of channel " + channel + " after " + exception + ":"); |
| 70 | + ioe.printStackTrace(); |
| 71 | + AMQConnection conn = (AMQConnection) channel.getConnection(); |
| 72 | + try { |
| 73 | + conn.close(AMQP.INTERNAL_ERROR, "Internal error closing channel for " + what, |
| 74 | + false, ioe); |
| 75 | + } catch (IOException ioeH) { |
| 76 | + // TODO: log the failure |
| 77 | + System.err.println("Failure during close of connection " + conn + " after " + ioe + ":"); |
| 78 | + ioeH.printStackTrace(); |
| 79 | + } |
74 | 80 | } |
75 | | - |
76 | 81 | } |
77 | 82 | } |
0 commit comments