@@ -535,10 +535,7 @@ private Message handle(@Nullable Delivery delivery) {
535
535
*/
536
536
@ Nullable
537
537
public Message nextMessage () throws InterruptedException , ShutdownSignalException {
538
- if (logger .isTraceEnabled ()) {
539
- logger .trace ("Retrieving delivery for " + this );
540
- }
541
- return handle (this .queue .take ());
538
+ return nextMessage (-1 );
542
539
}
543
540
544
541
/**
@@ -557,26 +554,35 @@ public Message nextMessage(long timeout) throws InterruptedException, ShutdownSi
557
554
if (!this .missingQueues .isEmpty ()) {
558
555
checkMissingQueues ();
559
556
}
560
- if (!cancelled ()) {
561
- Message message = handle (this .queue .poll (timeout , TimeUnit .MILLISECONDS ));
562
- if (message != null && cancelled ()) {
563
- this .activeObjectCounter .release (this );
564
- ConsumerCancelledException consumerCancelledException = new ConsumerCancelledException ();
565
- rollbackOnExceptionIfNecessary (consumerCancelledException ,
566
- message .getMessageProperties ().getDeliveryTag ());
567
- throw consumerCancelledException ;
557
+
558
+ if (this .transactional && cancelled ()) {
559
+ throw consumerCancelledException (null );
560
+ }
561
+ else {
562
+ Message message = handle (timeout < 0 ? this .queue .take () : this .queue .poll (timeout , TimeUnit .MILLISECONDS ));
563
+ if (cancelled () && (message == null || this .transactional )) {
564
+ Long deliveryTagToNack = null ;
565
+ if (message != null ) {
566
+ deliveryTagToNack = message .getMessageProperties ().getDeliveryTag ();
567
+ }
568
+ throw consumerCancelledException (deliveryTagToNack );
568
569
}
569
570
else {
570
571
return message ;
571
572
}
572
573
}
574
+ }
575
+
576
+ private ConsumerCancelledException consumerCancelledException (@ Nullable Long deliveryTagToNack ) {
577
+ this .activeObjectCounter .release (this );
578
+ ConsumerCancelledException consumerCancelledException = new ConsumerCancelledException ();
579
+ if (deliveryTagToNack != null ) {
580
+ rollbackOnExceptionIfNecessary (consumerCancelledException , deliveryTagToNack );
581
+ }
573
582
else {
574
583
this .deliveryTags .clear ();
575
- this .activeObjectCounter .release (this );
576
- ConsumerCancelledException consumerCancelledException = new ConsumerCancelledException ();
577
- rollbackOnExceptionIfNecessary (consumerCancelledException );
578
- throw consumerCancelledException ;
579
584
}
585
+ return consumerCancelledException ;
580
586
}
581
587
582
588
/*
0 commit comments