I need to write some code that only calls acknowledge if the session is synchronous because otherwise acknowledge throws a JMSCC0033 for not being able to call it against an async session (same as JMS Acknowledge Asynchronous Message) . However I cannot find a method or means to check the session itself. There is an internal implementation of isAsync, but nothing I can see externally. Would checking if there is a listener be enough? Am I totally missing something in the documentation?
This is library code, where the mode can be set via config, however I am fairly sure that it is ClientAcknowledge based on the user reports. This is a library that wants to clear all messages while closing, however runs into this exception periodically. From my decompiling the code I have come to the conclusion that it seems that there is no exposed way to check...which seems like a flaw since it can blow things up and has an internal mechanism to check it that seems easily exposable. Right now I am thinking I will have to just catch and swallow the exception...
You can use a session to create a
Producerto send messages asynchronously or you can use a session to create aConsumerand register aMessageListenerto receive messages asynchronously. However, there is no overall concept in JMS of a "sync" or "async" session.To be clear, it's perfectly acceptable to invoke
acknowledge()on theMessagereceived by theonMessage()method of aMessageListener. Here's some sample code that works perfectly well with ActiveMQ Artemis:It will print:
It's also worth keeping in mind that a JMS
Sessionis not thread-safe so if you're accessing the same session from multiple threads concurrently then you're going to have problems.