From 264a9ef9e2654bac4e78e06c8dd2d8ee15e4b5d9 Mon Sep 17 00:00:00 2001 From: Oliver Rice Date: Fri, 31 Jan 2025 11:35:46 -0600 Subject: [PATCH] remove refs to api in queues integration doc --- .../NavigationMenu.constants.ts | 1 - apps/docs/content/guides/queues/api.mdx | 62 ---------- .../docs/content/guides/queues/quickstart.mdx | 114 +----------------- 3 files changed, 2 insertions(+), 175 deletions(-) delete mode 100644 apps/docs/content/guides/queues/api.mdx diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts index 59d581a6436..dbdd5c15e17 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts @@ -1183,7 +1183,6 @@ export const queues: NavMenuConstant = { name: 'References', url: undefined, items: [ - { name: 'API', url: '/guides/queues/api' }, { name: 'PGMQ Extension', url: '/guides/queues/pgmq' }, ], }, diff --git a/apps/docs/content/guides/queues/api.mdx b/apps/docs/content/guides/queues/api.mdx deleted file mode 100644 index 35af17366b1..00000000000 --- a/apps/docs/content/guides/queues/api.mdx +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: API ---- - -{/* */} -When you create a Queue in Supabase, you can choose to create helper database functions in the `pgmq_public` schema. This schema exposes operations to manage Queue Messages to consumers client-side, but does not expose functions for creating or dropping Queues. - -Database functions in `pgmq_public` can be exposed via Supabase Data API so consumers client-side can call them. Visit the [Quickstart](/docs/guides/queues/quickstart) for an example. - -### `pgmq_public.pop(queue_name)` - -Retrieves the next available message and deletes it from the specified Queue. - -- `queue_name` (text): Queue name - ---- - -### `pgmq_public.send(queue_name, message, sleep_seconds)` - -Adds a Message to the specified Queue, optionally delaying its visibility to all consumers by a number of seconds. - -- `queue_name` (text): Queue name -- `message` (jsonb): Message payload to send -- `sleep_seconds` (integer, optional): Delay message visibility by specified seconds. Defaults to 0 - ---- - -### `pgmq_public.send_batch(queue_name, messages, sleep_seconds)` - -Adds a batch of Messages to the specified Queue, optionally delaying their availability to all consumers by a number of seconds. - -- `queue_name` (text): Queue name -- `messages` (jsonb[]): Array of message payloads to send -- `sleep_seconds` (integer, optional): Delay messages visibility by specified seconds. Defaults to 0 - ---- - -### `pgmq_public.archive(queue_name, message_id)` - -Archives a Message by moving it from the Queue table to the Queue's archive table. - -- `queue_name` (text): Queue name -- `message_id` (bigint): ID of the Message to archive - ---- - -### `pgmq_public.delete(queue_name, message_id)` - -Permanently deletes a Message from the specified Queue. - -- `queue_name` (text): Queue name -- `message_id` (bigint): ID of the Message to delete - ---- - -### `pgmq_public.read(queue_name, sleep_seconds, n)` - -Reads up to "n" Messages from the specified Queue with an optional "sleep_seconds" (visibility timeout). - -- `queue_name` (text): Queue name -- `sleep_seconds` (integer): Visibility timeout in seconds -- `n` (integer): Maximum number of Messages to read diff --git a/apps/docs/content/guides/queues/quickstart.mdx b/apps/docs/content/guides/queues/quickstart.mdx index dc810e96af1..9692ea368d9 100644 --- a/apps/docs/content/guides/queues/quickstart.mdx +++ b/apps/docs/content/guides/queues/quickstart.mdx @@ -4,7 +4,7 @@ subtitle: 'Learn how to use Supabase Queues to add and read messages' --- {/* */} -This guide is an introduction to interacting with Supabase Queues via the Dashboard and official client library. Check out [Queues API Reference](/docs/guides/queues/api) for more details on our API. +This guide is an introduction to interacting with Supabase Queues via the Dashboard. Check out [Queues SQL API Reference](/docs/guides/queues/pgmq) for more details on the SQL API. ## Concepts @@ -83,29 +83,9 @@ A "Basic Queue" will create `pgmq.q_` and `pgmq.a_` tabl However, an "Unlogged Queue" will create `pgmq.q_` as an unlogged table for better performance while sacrificing durability. The `pgmq.a_` table will still be created as a logged table so your archived messages remain safe and secure. -## Expose Queues to client-side consumers - -Queues, by default, are not exposed over Supabase Data API and are only accessible via Postgres clients. - -However, you may grant client-side consumers access to your Queues by enabling the Supabase Data API and granting permissions to the Queues API, which is a collection of database functions in the `pgmq_public` schema that wraps the database functions in the `pgmq` schema. - -This is to prevent direct access to the `pgmq` schema and its tables (RLS is not enabled by default on any tables) and database functions. - -To get started, navigate to the Queues [Settings page](/dashboard/project/_/integrations/queues/settings) and toggle on “Expose Queues via PostgREST”. Once enabled, Supabase creates and exposes a `pgmq_public` schema containing database function wrappers to a subset of `pgmq`'s database functions. - -Screenshot of Queues settings with toggle to expose to PostgREST - ### Enable RLS on your tables in `pgmq` schema -For security purposes, you must enable Row Level Security (RLS) on all Queue tables (all tables in `pgmq` schema that begin with `q_`) if the Data API is enabled. - -You’ll want to create RLS policies for any Queues you want your client-side consumers to interact with. +For security purposes, you may want to enable Row Level Security (RLS) on Queue tables (all tables in `pgmq` schema that begin with `q_`). Screenshot of creating an RLS policy from the Queues settings -### Grant permissions to `pgmq_public` database functions - -On top of enabling RLS and writing RLS policies on the underlying Queue tables, you must grant the correct permissions to the `pgmq_public` database functions for each Data API role. - -The permissions required for each Queue API database function: - -| **Operations** | **Permissions Required** | -| ------------------- | ------------------------ | -| `send` `send_batch` | `Select` `Insert` | -| `read` `pop` | `Select` `Update` | -| `archive` `delete` | `Select` `Delete` | - -To manage your queue permissions, click on the Queue Settings button. - -Screenshot of accessing queue settings - -Then enable the required roles permissions. - -Screenshot of configuring API access for roles from the Queues settings - - - -`postgres` and `service_role` roles should never be exposed client-side. - - - -### Enqueuing and dequeuing messages - -Once your Queue has been created, you can begin enqueuing and dequeuing Messages. - -Here's a TypeScript example using the official Supabase client library: - -```tsx -import { createClient } from '@supabase/supabase-js' - -const supabaseUrl = 'supabaseURL' -const supabaseKey = 'supabaseKey' - -const supabase = createClient(supabaseUrl, supabaseKey) - -const QueuesTest: React.FC = () => { - //Add a Message - const sendToQueue = async () => { - const result = await supabase.schema('pgmq_public').rpc('send', { - queue_name: 'foo', - message: { hello: 'world' }, - sleep_seconds: 30, - }) - console.log(result) - } - - //Dequeue Message - const popFromQueue = async () => { - const result = await supabase.schema('pgmq_public').rpc('pop', { queue_name: 'foo' }) - console.log(result) - } - - return ( -
-

Queue Test Component

- - -
- ) -} - -export default QueuesTest -```