I want to know what happens when we receive ACK. Do we receive ACKs in a single thread or in many threads?
Do handleAck and handleNack methods are used by a single thread or many threads? If they are used by a single thread then it is OK. But if they are used by several threads then we have to construct our code in the thread safe manner.
You shouldn't need to write your
ConfirmListener code thread-safe but not because the
nack methods won't be called from multiple threads but because you shouldn't share a
Channel between threads to begin with.
The documentation specifically calls this out:
While some operations on channels are safe to invoke concurrently, some are not and will result in incorrect frame interleaving on the wire. Sharing channels between threads will also interfere with * Publisher Confirms.
When you are publishing to the broker just don't share the Channel. Channels are lightweight and not that expensive to create. That way you don't need to worry about the confirms either.
If you do share the Channel your confirms will be interfered with as per the above quote.