cshannon commented on code in PR #1616:
URL: https://github.com/apache/activemq/pull/1616#discussion_r2708655637


##########
activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java:
##########
@@ -771,6 +778,9 @@ void clearMessagesInProgress() {
                     // ensure unconsumed are rolledback up front as they may 
get redelivered to another consumer
                     List<MessageDispatch> list = 
unconsumedMessages.removeAll();
                     if (!this.info.isBrowser()) {
+                        if (session.isTransacted()) {
+                            
capturePrefetchedMessagesForDuplicateSuppression(list);

Review Comment:
   This method iterates over the list and then right below we iterate again to 
rollback duplicates. Im curious if we can somehow refactor to just iterate 
once. Maybe something like:
   
   ```java
   for (MessageDispatch old : list) {
       if (session.isTransacted()) {
           capturePrefetchedMessagesForDuplicateSuppression(old);
       }
       session.connection.rollbackDuplicate(this, old.getMessage());
   }
   ```
   
   ```java
   private void capturePrefetchedMessagesForDuplicateSuppression(final 
MessageDispatch pending) {
       if (previouslyDeliveredMessages == null) {
           previouslyDeliveredMessages = new 
PreviouslyDeliveredMap<>(session.getTransactionContext().getTransactionId());
       }
       if (pending.getMessage() != null) {
           previouslyDeliveredMessages.put(pending.getMessage().getMessageId(), 
new PreviouslyDelivered(pending, false, true));
       }
       LOG.trace("{} tracking existing transacted {} prefetched ({})", 
getConsumerId(), previouslyDeliveredMessages.transactionId, pending);
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to