[ 
https://issues.apache.org/jira/browse/AMQ-8464?focusedWorklogId=883104&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-883104
 ]

ASF GitHub Bot logged work on AMQ-8464:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Oct/23 12:30
            Start Date: 03/Oct/23 12:30
    Worklog Time Spent: 10m 
      Work Description: 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:
   Edit:
   
   I think you can greatly simply this to just be:
   
   ```java
   <T> T receiveBody(Class<T> bodyType, long timeout) throws JMSException {
           Message message = receive(timeout);
           return message != null ? message.getBody(bodyType) : null;
   }
   ```





Issue Time Tracking
-------------------

    Worklog Id:     (was: 883104)
    Time Spent: 1h 10m  (was: 1h)

> Implement JMS 2.0 Consumer receiveBody
> --------------------------------------
>
>                 Key: AMQ-8464
>                 URL: https://issues.apache.org/jira/browse/AMQ-8464
>             Project: ActiveMQ
>          Issue Type: Task
>            Reporter: Matt Pavlovich
>            Assignee: Matt Pavlovich
>            Priority: Major
>              Labels: #jms2
>             Fix For: 6.0.0, 5.18.3
>
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to