liveBook · Manning

Visibility timeout

As explained in Just Use Postgres!

A visibility timeout is a queue-delivery interval during which a retrieved message remains hidden from other consumers before becoming available again if it is not acknowledged or removed.

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

How Just Use Postgres! covers it

How deep it goes
Explains retrieval, hiding, expiration, reappearance, and archiving through a runnable two-minute example.
Examples
Uses a driving-license visitor queue, Noah Bennett, a 120-second timeout, and pgmq.archive.
What it assumes
Assumes a created pgmq queue and enqueued JSON messages, while introducing visibility behavior through visitor processing.
What you can do after
Operate/configure pgmq.read with a timeout and archive successfully processed messages.
How it connects
Connects queue consumers with message processing failover, message retrieval, deletion, and archiving.

Also explained in

Compare how 2 books explain visibility timeout →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.