[
https://issues.apache.org/jira/browse/AMQ-8464?focusedWorklogId=1005656&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1005656
]
ASF GitHub Bot logged work on AMQ-8464:
---------------------------------------
Author: ASF GitHub Bot
Created on: 17/Feb/26 17:08
Start Date: 17/Feb/26 17:08
Worklog Time Spent: 10m
Work Description: tabish121 commented on code in PR #1543:
URL: https://github.com/apache/activemq/pull/1543#discussion_r2818095361
##########
activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java:
##########
@@ -580,20 +594,93 @@ private boolean redeliveryExceeded(MessageDispatch md) {
* this message consumer is concurrently closed
*/
@Override
- public Message receive() throws JMSException {
- checkClosed();
- checkMessageListener();
-
- sendPullCommand(0);
- MessageDispatch md = dequeue(-1);
- if (md == null) {
- return null;
+ public Message receive() {
+ try {
+ checkClosed();
+ checkMessageListener();
+
+ sendPullCommand(0);
+ MessageDispatch md = dequeue(-1);
+ if (md == null) {
+ return null;
+ }
+
+ beforeMessageIsConsumed(md);
+ afterMessageIsConsumed(md, false);
+
+ return createActiveMQMessage(md);
+ } catch (JMSException e) {
+ throw JMSExceptionSupport.convertToJMSRuntimeException(e);
}
+ }
- beforeMessageIsConsumed(md);
- afterMessageIsConsumed(md, false);
+ /**
+ * Receives the next message and returns its body converted to the
requested type.
+ * <p>
+ * This call follows the same synchronous consume flow as {@link
#receive()}:
+ * pull/dequeue, mark delivered, then acknowledge bookkeeping after
successful
+ * conversion. Conversion failures are delegated to
+ * {@link #handleReceiveBodyFailure(MessageDispatch,
MessageFormatException)}
+ * before rethrowing the {@link MessageFormatException}.
+ *
+ * @param bodyType
+ * the expected body type.
+ *
+ * @return the converted message body, or {@code null} if no message is
available.
+ */
+ @Override
+ public <T> T receiveBody(Class<T> bodyType) {
+ try {
+ checkClosed();
+ checkMessageListener();
- return createActiveMQMessage(md);
+ sendPullCommand(0);
+ MessageDispatch md = dequeue(-1);
+ if (md == null) {
+ return null;
+ }
+
+ beforeMessageIsConsumed(md);
Review Comment:
I think you could avoid a lot of complexity here by deferring
`beforeMessageIsConsumed(md);` until after you've actually checked that you
want to consume the message and if you can't / won't because the body is not
assignable to the target you just enqueue the message back into the head of the
unconsumed list as you haven't consumed it. That way you don't need to perform
the various rollback work since you won't have done anything that triggers
actual tracking work in the consumer.
Issue Time Tracking
-------------------
Worklog Id: (was: 1005656)
Time Spent: 3h 50m (was: 3h 40m)
> Implement JMS 2.0 Consumer receiveBody
> --------------------------------------
>
> Key: AMQ-8464
> URL: https://issues.apache.org/jira/browse/AMQ-8464
> Project: ActiveMQ
> Issue Type: New Feature
> Reporter: Matt Pavlovich
> Assignee: Jean-Baptiste Onofré
> Priority: Major
> Labels: #jms2
> Fix For: 6.3.0
>
> Time Spent: 3h 50m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact