Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of a JMS session?

Tags:

What is the purpose of a JMS session? Why isn't a connection alone sufficient to exchange JMS messages between senders and receivers?

like image 818
Derek Mahar Avatar asked Apr 21 '10 20:04

Derek Mahar


People also ask

What is a JMS session?

A session is a single-threaded context for producing and consuming messages. You use sessions to create the following: Message producers. Message consumers.

What is the purpose of JMS?

The Java Message Service (JMS) was designed to make it easy to develop business applications that asynchronously send and receive business data and events. It defines a common enterprise messaging API that is designed to be easily and efficiently supported by a wide range of enterprise messaging products.

How does a JMS queue work?

A JMS Queue implements load balancer semantics. A single message will be received by exactly one consumer. If there are no consumers available at the time the message is sent it will be kept until a consumer is available that can process the message.

What is session in Java?

The time interval in which two systems(i.e. the client and the server) communicate with each other can be termed as a session. In simpler terms, a session is a state consisting of several requests and response between the client and the server.


1 Answers

I had the same question and that's what lead me here. Quoting the Doc is not very helpful in this case, as I'm sure OP's question is not about how to use sessions, or what do they do, but why do they really exist, why not combine their capability with Connection. IMHO, this is a meta question.

Loosely speaking Sessions are essentially a thread's view into a Connection, Here is what the JMS spec has to say about the relation between a thread and a Session while accessing the later.

There are no restrictions on the number of threads that can use a session or any objects it creates. The restriction is that the resources of a session should not be used concurrently by multiple threads. It is up to the user to ensure that this concurrency restriction is met. The simplest way to do this is to use one thread. In the case of asynchronous delivery, use one thread for setup in stopped mode and then start asynchronous delivery. In more complex cases the user must provide explicit synchronization.

From the messaging point of view, they hold a logical unit of work. That's why the Transactions got coupled with the Sessions as well.

Having said that, quite often there will be 1:1 mapping between a connection and a Session. That's why I think JMSContext got introduced in 2.0. to simplify things.

Looking at the date of OP's post I think I am almost a decade late. :D

like image 64
amritanshu Avatar answered Sep 25 '22 09:09

amritanshu