|
23 | 23 | import com.rabbitmq.client.Command; |
24 | 24 | import com.rabbitmq.client.Connection; |
25 | 25 | import com.rabbitmq.client.Consumer; |
| 26 | +import com.rabbitmq.client.ConsumerCancellationListener; |
26 | 27 | import com.rabbitmq.client.Envelope; |
27 | 28 | import com.rabbitmq.client.FlowListener; |
28 | 29 | import com.rabbitmq.client.GetResponse; |
@@ -90,6 +91,8 @@ public class ChannelN extends AMQChannel implements com.rabbitmq.client.Channel |
90 | 91 | */ |
91 | 92 | public volatile ConfirmListener confirmListener = null; |
92 | 93 |
|
| 94 | + public volatile ConsumerCancellationListener consumerCancellationListener = null; |
| 95 | + |
93 | 96 | /** Sequence number of next published message requiring confirmation. |
94 | 97 | */ |
95 | 98 | private long nextPublishSeqNo = 0L; |
@@ -175,6 +178,15 @@ public void setDefaultConsumer(Consumer consumer) { |
175 | 178 | defaultConsumer = consumer; |
176 | 179 | } |
177 | 180 |
|
| 181 | + public ConsumerCancellationListener getConsumerCancellationListener() { |
| 182 | + return consumerCancellationListener; |
| 183 | + } |
| 184 | + |
| 185 | + public void setConsumerCancellationListener( |
| 186 | + ConsumerCancellationListener listener) { |
| 187 | + consumerCancellationListener = listener; |
| 188 | + } |
| 189 | + |
178 | 190 | /** |
179 | 191 | * Protected API - sends a ShutdownSignal to all active consumers. |
180 | 192 | * @param signal an exception signalling channel shutdown |
@@ -339,6 +351,16 @@ public void releaseChannelNumber() { |
339 | 351 | // be handled by whichever RPC continuation invoked Recover, |
340 | 352 | // so return false |
341 | 353 | return false; |
| 354 | + } else if (method instanceof Basic.Cancel) { |
| 355 | + ConsumerCancellationListener l = getConsumerCancellationListener(); |
| 356 | + if (l != null) { |
| 357 | + try { |
| 358 | + l.handleConsumerCancellation(((Basic.Cancel)method).getConsumerTag()); |
| 359 | + } catch (Throwable ex) { |
| 360 | + _connection.getExceptionHandler().handleConsumerCancellationException(this, ex); |
| 361 | + } |
| 362 | + } |
| 363 | + return true; |
342 | 364 | } else { |
343 | 365 | return false; |
344 | 366 | } |
|
0 commit comments