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