Affects: 5.3.31

There is a problem with receiving large messages (files with size > 100 KB) using Spring JmsTemplate from ActiveMQ Artemis JMS. We send and receive a message (ByteMessage) without errors, but can't read bytes from received message. During the debug process, I came across the fact that sometimes the error does not occur (and we receive the file).

Error log:

Exception in thread "main" java.lang.RuntimeException: AMQ219023: The large message lost connection with its session, either because of a rollback or a closed session at org.apache.activemq.artemis.core.client.impl.ClientLargeMessageImpl.getBodyBuffer(ClientLargeMessageImpl.java:91) at org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage.readBytes(ActiveMQBytesMessage.java:223) at org.raliev.MessageReceiver.writeToFile(MessageReceiver.java:31) at org.raliev.MessageReceiver.receive(MessageReceiver.java:24) at org.raliev.Main.main(Main.java:27) Caused by: ActiveMQIllegalStateException[errorType=ILLEGAL_STATE message=AMQ219023: The large message lost connection with its session, either because of a rollback or a closed session] at org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl.saveBuffer(LargeMessageControllerImpl.java:265) at org.apache.activemq.artemis.core.client.impl.ClientLargeMessageImpl.checkBuffer(ClientLargeMessageImpl.java:157) at org.apache.activemq.artemis.core.client.impl.ClientLargeMessageImpl.getBodyBuffer(ClientLargeMessageImpl.java:89) ... 4 more

My stack: - JDK 17 (liberica) - ActiveMQ Artemis JMS server: 2.28.0 - ActiveMQ Artemis JMS client: 2.28.0 - Spring-JMS: 5.3.31

To reproduce: 1. clone: https://github.com/Recon838/spring-jms-large-message-receive-problem 2. start ActiveMQ Artemis JMS 3. run: org.raliev.Main

Comment From: snicoll

Thanks for the report, but that's not related to JmsTemplate if you chose to use a blocking scenario like the one in your use case. ActiveMQ considers a large file to not be held in memory but streamed from the broker and copying its content requires the session to still be opened, which does not happen that blocking receive method.

This SO thread has more details as well as several options to deal with this use case.