pgmq.read retrieves messages without deleting them immediately. A visibility timeout temporarily hides each retrieved message from other consumers, then makes it available again if processing fails or remains incomplete. section 11.7.2
pgmq.read( queue_name text, vt integer, qty integer, conditional jsonb DEFAULT '{}'::jsonb)
Use queue_name to select the queue, vt to set the visibility window in seconds, qty to choose the number of messages, and conditional to filter JSON payloads. section 11.7.2
Reserve a visitor for two minutes
SELECT msg_id, message, enqueued_at FROM pgmq.read( queue_name => 'visitors_queue', vt => 120, qty => 1 ); The selected visitor disappears from other consumers during the two-minute window. If processing succeeds, archive the message with pgmq.archive; otherwise, let the timeout expire so another consumer can retrieve it. section 11.7.2
The processing flow is:
- Read one or more messages and temporarily reserve them. section 11.7.2
- Complete processing and archive the message, or allow visibility to return after failure. section 11.7.2
