A visibility timeout temporarily hides a retrieved queue message from other consumers. If processing does not finish before the interval expires, the message becomes visible again for another attempt. section 11.7.2
Use the timeout when processing may fail or when a consumer must have a limited response window:
- Read without immediately deleting the message. section 11.7.2
- Set vt to the required number of seconds; qty controls how many messages are retrieved. section 11.7.2
- Delete or archive the message after successful processing; otherwise, let the timeout return it to the queue. section 11.7.2
Give a visitor two minutes to respond
SELECT msg_id, message, enqueued_at FROM pgmq.read( queue_name => 'visitors_queue', vt => 120, qty => 1 ); The retrieved visitor stays hidden for two minutes. If the visitor does not arrive, the record becomes visible again; after successful service, archive it with pgmq.archive. section 11.7.2
Listing 11.10 Retrieving the next visitor with a two-minute visibility timeout
SELECT msg_id, message, enqueued_at FROM pgmq.read( queue_name => 'visitors_queue', vt => 120, qty => 1 );
Run the two-minute pgmq.read example and compare the queue before expiration, after expiration, and after archiving. section 11.7.2

