I have a message listener (using ActiveMQ) that implements SessionAwareMessageListener. When the onMessage(Message,Session) method is called, I parse the message and pass off its handling to a processor, along with the session for performing rollback/commit.
I need to create a new message, for placing onto an external queue. Is it ok for me to use that existing session to create the message (which I’m doing currently), or should I in fact be creating a new session, with which to create it? I’m a little hazy on exactly how JMS sessions work.
Sessions share a Connection which is usually one TCP connection. Different Connections can be to different servers or use different TCP connections.
A session is single threaded. This means the messages you receive or send in the session will be in a predictable order. If you send two messages on two different sessions they can arrive in any order. (Some times this is preferable)
In the simplest use case, you will have one connection with one session.