Setting up the JMS application v42.7.3.3
After creating the queue table and queue for the message types and starting the queue, you can set up your JMS application:
- Create a connection factory.
- Create a connection using the connection factory.
- Create a session using the connection.
- Get the queue from the session.
- Create a message producer using the session and queue to send messages.
- Create a message consumer using the session and queue to receive messages.
Connection factory
Use the connection factory to create connections. EDBJmsConnectionFactory is an implementation of ConnectionFactory and QueueConnectionFactory, which you use to create Connection and QueueConnection. You can create a connection factory using one of the constructors of the EDBJmsConnectionFactory class. You can use all three constructors to create either a ConnectionFactory or QueueConnectionFactory.
//Constructor with connection related properties. public EDBJmsConnectionFactory(String host, int port, String database, String username, String password); //Constructor with connection string, user name and password. public EDBJmsConnectionFactory(String connectionString, String username, String password); //Constructor with SQL Connection. public EDBJmsConnectionFactory(java.sql.Connection connection);
This example shows how to create a ConnectionFactory using an existing java.sql.Connection:
javax.jms.ConnectionFactory connFactory = new EDBJmsConnectionFactory(connection);
This example shows how to create a QueueConnectionFactory using a connection string, username, and password:
javax.jms.QueueConnectionFactory connFactory = new EDBJmsConnectionFactory ("jdbc:edb//localhost:5444/edb", "enterprisedb", "edb");
Connection
A connection is a client's active connection that can be created from the ConnectionFactory and used to create sessions. EDBJmsConnection is an implementation of Connection, and EDBJmsQueueConnection is an implementation of QueueConnection and extends EDBJmsConnection. You can create a Connection using ConnectionFactory and a QueueConnection from QueueConnectionFactory.
This example shows how to create a Connection and a QueueConnection: