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


##########
activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java:
##########
@@ -675,6 +705,49 @@ public Message receive(long timeout) throws JMSException {
         return null;
     }
 
+    /**
+     * JMS 2.0 support method for receiveBody(long timeout)
+     * AMQ-8464
+     */
+    <T> T receiveBody(Class<T> bodyType, long timeout) throws JMSException {
+        checkClosed();
+        checkMessageListener();
+        if (timeout == 0) {
+            return this.receiveBody(bodyType);
+        }
+
+        sendPullCommand(timeout);
+        while (timeout > 0) {
+
+            MessageDispatch md;
+            if (info.getPrefetchSize() == 0) {
+                md = dequeue(-1); // We let the broker let us know when we 
timeout.
+            } else {
+                md = dequeue(timeout);
+            }
+
+            if (md == null) {
+                return null;
+            }
+
+            beforeMessageIsConsumed(md);
+            Message message = createActiveMQMessage(md);
+
+            try {
+                // This throws MessageFormatException if body is not of 
bodyType
+                T body = message.getBody(bodyType);
+                afterMessageIsConsumed(md, false);
+                return body;
+            } catch (MessageFormatException e) {
+                synchronized (unconsumedMessages.getMutex()) {
+                    unconsumedMessages.enqueueFirst(md);

Review Comment:
   I would think the method should just simply be this:
   
   ```java
   <T> T receiveBody(Class<T> bodyType) throws JMSException {
     checkClosed();
     checkMessageListener();
   
     sendPullCommand(0);
     MessageDispatch md = dequeue(-1);
     if (md == null) {
         return null;
     }
   
     beforeMessageIsConsumed(md);
     afterMessageIsConsumed(md, false);
   
     Message message = createActiveMQMessage(md);
     return message.getBody(bodyType);
   }
   ```



-- 
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]

Reply via email to