SQL/MX Queuing and Publish/Subscribe Services
Major Queuing Features
HP NonStop SQL/MX Queuing and Publish/Subscribe Services—523734-002
2-13
Partitioned Queues
For additional information on how to use rowsets, see the SQL/MX Programming
Guide for C and COBOL.
Partitioned Queues
Partitioned queues and channels allow applications to scale queues and channels
across clusters and use data dependent routing to balance the load across the
individual devices in a cluster.
For example, this CREATE TABLE statement allows partitioning of the inbox table by
the value of the destination column:
CREATE TABLE psdb.pubs.inbox
(destination INT NOT NULL,
origin INT NOT NULL,
label INT,
priority INT,
PRIMARY KEY (destination, origin)
)
PARTITION (ADD FIRST KEY 230 LOCATION $DATA05,
ADD FIRST KEY 260 LOCATION $DATA06
);
The inbox table has been partitioned into three partitions by using the value of the
destination column. For each partition, a single server can dequeue entries.
/* Declare cursor */
EXEC SQL DECLARE get_arrivals CURSOR WITH HOLD FOR
SELECT destination, origin FROM
(DELETE FROM STREAM(inbox)
WHERE destination BETWEEN :start AND :end
FOR SKIP CONFLICT ACCESS) AS inbox;
...
start = 230; end = 259;
EXEC SQL BEGIN WORK; /* Start transaction */
EXEC SQL OPEN get_arrivals; /* Open cursor */
/* Wait for arrivals */
while (1) {
/* Dequeue arrivals */
EXEC SQL FETCH get_arrivals
INTO :hv_destination, :hv_origin;
...
/* Commit does not close open cursor */
EXEC SQL COMMIT WORK; /* Commit transaction */
EXEC SQL BEGIN WORK; /* Start new transaction */
}
EXEC SQL COMMIT WORK; /* Commit final transaction */
...
Note. This example uses partitioning syntax for SQL/MX tables.