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