create_queue
SQL 0.1.1 · Source cbff27b8a34e1384384018680e46c20d5c610cc9.
Signature
postgremq.create_queue(p_queue_name character varying, p_topic_name character varying, p_max_attempts integer DEFAULT 0, p_exclusive boolean DEFAULT false, p_keep_alive_interval interval DEFAULT '00:05:00'::interval)
RETURNS uuid
The signature, defaults, and result above were extracted from the installed PostgreSQL catalog.
Create or reuse a named subscription
The topic must exist. Returns the queue incarnation UUID. Identical redeclaration preserves deliveries and returns the existing generation; different topic, attempt limit, or lifetime settings fail. Zero attempts means unlimited. Exclusive lifetime starts at declaration and live redeclaration renews it; an expired queue cannot be revived. Lifetime must be positive even for a Durable queue.
Transactions and errors
PMQ03: invalid names, negative attempts, invalid lifetime, or incompatible redeclaration. PMQ02: missing topic or expired Exclusive redeclaration. A concurrent topic deletion can produce 23503. Redeclaration locks the existing queue until transaction end; commit promptly. NULL max-attempts/exclusive can produce 23502.
All calls require the applicable caller privileges. See SQL errors for driver failures and uncertain outcomes.
Example
Run in psql with ON_ERROR_STOP and fresh reference-* names. ROLLBACK removes the fixtures.
BEGIN;
SELECT postgremq.create_topic('reference-events');
SELECT postgremq.create_queue('reference-jobs', 'reference-events', 5, false);
SELECT postgremq.create_queue('reference-jobs', 'reference-events', 5, false);
ROLLBACK;
Both queue calls return one generation. Replacing the queue by deletion/recreation would return a different identity.
Related: Durable queues, SQL conventions.