Advanced queueing is available in JDBC 42.3.2.1 and later.
EDB Postgres Advanced Server advanced queueing provides message queueing and message processing for the EDB Postgres Advanced Server database. User-defined messages are stored in a queue, and a collection of queues is stored in a queue table. You must first create a queue table before creating a queue that depends on it.
On the server side, procedures in the DBMS_AQADM package create and manage message queues and queue tables. Use the DBMS_AQ package to add or remove messages from a queue or register or unregister a PL/SQL callback procedure. For more information about DBMS_AQ and DBMS_AQADM, see the EDB Postgres Advanced Server documentation.
On the client side, the application uses EDB-JDBC driver's JMS API to enqueue and dequeue message.
Enqueueing or dequeueing a message
For more information about using EDB Postgres Advanced Server's advanced queueing functionality, see Built-in packages.
Server-side setup
To use advanced queueing functionality on your JMS-based Java application, first create a user-defined type, queue table, and queue. Then start the queue on the database server. You can use either EDB-PSQL or EDB-JDBC JMS API in the Java application.
Using EDB-PSQL
Invoke EDB-PSQL and connect to the EDB Postgres Advanced Server host database. Use the following SPL commands at the command line.
Creating a user-defined type
To specify a RAW data type, create a user-defined type. This example creates a user-defined type named as mytype.
Create the queue table
A queue table can hold multiple queues with the same payload type. This example creates a table named MSG_QUEUE_TABLE.
Create the queue
This example creates a queue named MSG_QUEUE in the table MSG_QUEUE_TABLE.
Start the queue
Once the queue is created, invoke the following SPL code at the command line to start a queue in the EDB database.
Using EDB-JDBC JMS API
The following JMS API calls perform the same steps performed using EDB-PSQL to:
Connect to the EDB Postgres Advanced Server database
Create the user-defined type
Create the queue table and queue
Start the queue
Client-side example
After you create a user-defined type followed by queue table and queue, start the queue. Then, you can enqueue or dequeue a message using EDB-JDBC driver's JMS API.
Create a Java project and add the edb-jdbc18.jar from the edb-jdbc installation directory to its libraries.
Create a Java Bean corresponding to the type you created.
Enqueue and dequeue a message
To enqueue and dequeue a message:
Create a JMS connection factory and create a queue connection.
Create a queue session.
Enqueue a message
To enqueue a message:
Create EDBJmsMessageProducer from the session.
Create the enqueue message.
Call the EDBJmsMessageProducer.send method.
Dequeue a message
To dequeue a message:
Create EDBJmsMessageConsumer from the session.
Call the EDBJmsMessageConsumer.Receive method.
A complete enqueue and dequeue program
This example shows enqueue and dequeue. User-defined type, queue table, and queue are created using EDB-PSQL, and the queue is started.
This example shows enqueue, dequeue, and creating the user-defined type, queue table, and queue. It also starts the queue.