Setting up JMS application v42.7.3.1
After creating the queue table and queue for the message types and starting the queue, you can follow these steps to 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
The Connection factory
is used to create connections. EDBJmsConnectionFactory
is an implementation of ConnectionFactory
and QueueConnectionFactory
, used to create Connection
and QueueConnection
. A Connection factory
can be created using one of the constructors of the EDBJmsConnectionFactory
class. All three constructors can be used to create either a ConnectionFactory
or QueueConnectionFactory
.
This example shows how to create a ConnectionFactory
using an existing java.sql.Connection
:
This example shows how to create a QueueConnectionFactory
using a connection string, username, and password:
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
, while EDBJmsQueueConnection
is an implementation of QueueConnection
and extends EDBJmsConnection
. A Connection
can be created using ConnectionFactory
, while QueueConnection
can be created from QueueConnectionFactory
.
This example shows how to create a Connection
and a QueueConnection
:
A connection must be started in order for the consumer to receive messages. On the other hand, a producer can send messages without starting the connection.
This example shows how to start a connection:
A connection can be stopped at any time to cease receiving messages, and can be restarted when needed. However, a closed connection cannot be restarted.
This example shows how to stop and close the connection:
Session
The Session
in EDBJms is used for creating producers and consumers, and for sending and receiving messages. EDBJmsSession
implements the basic Session
functionality, while EDBJmsQueueSession
extends EDBJmsSession
and implements QueueSession
. A Session
can be created from a Connection
.
This example shows how to create a Session
and a QueueSession
:
A Session
or QueueSession
is also used to create queues.
Important
In this context, "creating a queue" does not refer to physically creating the queue. As discussed earlier, the queue needs to be created and started as part of the server-side setup. In this context, creating a queue means getting the queue, related queue table, and payload type that have already been created.
This example shows how to create a queue:
Message producer
A Message producer
is responsible for creating and sending messages. It is created using a session and queue. EDBJmsMessageProducer
is an implementation of MessageProducer
, but in most cases, you will be using the standard MessageProducer
.
This example shows how to create a message producer, create a message, and send it. Creating messages of different types will be discussed in the following sections.
Message consumer
A Message consumer
is used to receive messages. It is created using a session and a queue. EDBJmsMessageConsumer
is an implementation of MessageConsumer
, but you will most often use the standard MessageConsumer
.
This example shows how to create a message consumer and receive a message: