Creating JMS Connections

When the appropriate JMS property values are set, call one of the following methods to create a JMS connection:

  • createConnection()—creates a JMS connection with the client authentication credentials provided through the System, Initial Context, JNDI, URL, and/or Connection Factory property sources.
  • createXAConnection()—creates a JMS connection that supports XA Sessions with the client authentication credentials provided through the System, Initial Context, JNDI, URL, and/or Connection Factory property sources.
  • createConnection(String username, String password)—When using basic client authentication (the default), this method creates a JMS connection using an explicit username and password. The provided username and password overwrite any value that was implicitly set through other JMS property sources.
  • createXAConnection(String username, String password)—When using basic client authentication (the default), use this method to establish a JMS connection that supports XA Sessions using an explicit username and password. The provided username and password overwrite any value that was implicitly set through other JMS property sources.
Note  
  • If a Connection Factory or XAConnection Factory object is looked up from the message broker (refer to Working with JNDI), the properties set for the JNDI connection are inherited by the subsequent JMS connection. A client can use these same JMS properties for the JMS connection or choose to override them with new values when making the JMS connection. For information on where each property can be specified, and the priority that is given to the property according to where it is specified, refer to JMS Properties Reference.
  • By default, each JMS connection that is created uses its own processing context and thread. If you want each new connection to use the default context and its single processing thread, set the InitialContext environment property SOLACE_JMS_USE_DEFAULT_CONTEXT property to true.

Starting JMS Connections

To begin receiving messages over a JMS connection, the client application must call the start() method after the connection is established.

Stopping or Closing JMS Connections

To stop or close a JMS connection, call one of the following methods:

  • Connection.stop()—Temporarily stops the delivery of incoming messages over the connection. When a connection is stopped, the delivery of messages to the connection’s consumers is inhibited: synchronous receives block, and messages are not delivered to message listeners. To restart the delivery of messages, call Connection.start().

    When using Guaranteed Transport, published Non-Persistent and Persistent messages are spooled for consumers when the connection is stopped; when the connection is restarted, the spooled messages are delivered. When using Direct Transport, the Non-Persistent messages are not spooled for consumers when the connection is stopped and they are discarded.

  • Connection.close()—Closes the connection.