Name

Connection

Synopsis

A JMS client needs to have a Connection to the JMS provider in order to send or receive messages. The javax.jms.Connection interface for messaging is roughly analogous to the java.sql.Connection interface in JDBC -- one connects a client to a messaging service, the other connects a client to a persistent data service. Another analogous property is that JMS Connections are generally expensive to create, because setup requires networks communications with the provider. A client will normally want to have only one, or very few, Connections to their JMS provider.

A Connection can be in either running mode (messages are being sent and received through the connection), or it can be stopped. When a Connection is in stopped mode, it can send messages, but it can’t receive messages. A newly-created Connection is in stopped mode, to allow you to finish setting up your client (create Session(s), create MessageConsumers and/or MessageProducers, etc.). A Connection can be started and stopped (using the stop() and start() methods) multiple times, if necessary. When you’re done with a Connection, you should free up its resources by calling its close() method.

Connections are used to create sessions for message exchanges. The methods for creating sessions are defined on extensions of the Connection interface (QueueConnection and TopicConnection).

public interface Connection {
// Public Instance Methods
   public abstract void close() throws JMSException; public abstract String ...

Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.