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


##########
activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java:
##########
@@ -589,6 +590,35 @@ public Message receive() throws JMSException {
         return createActiveMQMessage(md);
     }
 
+    /**
+     * JMS 2.0 support method for receiveBody(bodyType)
+     * AMQ-8464
+     */
+    <T> T receiveBody(Class<T> bodyType) throws JMSException {
+        checkClosed();
+        checkMessageListener();
+
+        sendPullCommand(0);
+        MessageDispatch md = dequeue(-1);
+        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()) {

Review Comment:
   Ok so based on the spec I think we should only be re-enqueing for certain 
ack modes: 
https://jakarta.ee/specifications/messaging/3.0/apidocs/jakarta/jms/jmsconsumer#receiveBody-java.lang.Class-
   
   For example this is qpid jms: 
   
   
https://github.com/apache/qpid-jms/blob/149eeb01027120d84af3a62eb83858c86d244b90/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java#L257-L264
   
    ```java
    // Should behave as if receiveBody never happened in these modes.
     if (acknowledgementMode == Session.AUTO_ACKNOWLEDGE ||
         acknowledgementMode == Session.DUPS_OK_ACKNOWLEDGE) {
   
   
         envelope.setEnqueueFirst(true);
         onInboundMessage(envelope);
         envelope = null;
     }
   ```



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