@@ -293,6 +293,88 @@ const federation = createFederation({
293293[ `AmqpMessageQueue` ] : https://jsr.io/@fedify/amqp/doc/mq/~/AmqpMessageQueue
294294[ RabbitMQ ] : https://www.rabbitmq.com/
295295
296+ ### [ ` MysqlMessageQueue ` ]
297+
298+ * This API is available since Fedify 2.1.0.*
299+
300+ To use [ ` MysqlMessageQueue ` ] , you need to install the * @fedify/mysql * package
301+ first:
302+
303+ ::: code-group
304+
305+ ~~~~ bash [Deno]
306+ deno add jsr:@fedify/mysql
307+ ~~~~
308+
309+ ~~~~ bash [npm]
310+ npm add @fedify/mysql mysql2
311+ ~~~~
312+
313+ ~~~~ bash [pnpm]
314+ pnpm add @fedify/mysql mysql2
315+ ~~~~
316+
317+ ~~~~ bash [Yarn]
318+ yarn add @fedify/mysql mysql2
319+ ~~~~
320+
321+ ~~~~ bash [Bun]
322+ bun add @fedify/mysql mysql2
323+ ~~~~
324+
325+ :::
326+
327+ [ ` MysqlMessageQueue ` ] is a message queue implementation that uses a MySQL or
328+ MariaDB database as the backend. Since MySQL and MariaDB do not provide a
329+ ` LISTEN ` /` NOTIFY ` mechanism, it uses ** polling** to discover new messages.
330+ The polling interval is configurable and defaults to 1 second to minimize
331+ latency; this is shorter than the default for PostgreSQL-backed queues.
332+
333+ Concurrent workers are safely supported via ` SELECT … FOR UPDATE SKIP LOCKED `
334+ and MySQL advisory locks (` GET_LOCK ` /` RELEASE_LOCK ` ).
335+
336+ > [ !NOTE]
337+ > ` MysqlMessageQueue ` requires MySQL 8.0+ or MariaDB 10.6+ for
338+ > ` SELECT … FOR UPDATE SKIP LOCKED ` support.
339+
340+ > [ !NOTE]
341+ > Because ` MysqlMessageQueue ` uses polling rather than a push-based
342+ > notification system, there is an inherent latency between when a message
343+ > is enqueued and when it is delivered. With the default 1-second poll
344+ > interval, messages may take up to 1 second to be picked up. You can
345+ > lower the ` pollInterval ` option to reduce this latency at the cost of
346+ > additional database load.
347+
348+ Best for
349+ : Production use in systems that already use MySQL or MariaDB.
350+
351+ Pros
352+ : Persistent, supports multiple workers, minimal additional infrastructure
353+ for MySQL/MariaDB users.
354+
355+ Cons
356+ : Polling-based delivery (up to ` pollInterval ` latency); requires
357+ MySQL 8.0+ or MariaDB 10.6+.
358+
359+ ~~~~ typescript twoslash
360+ import type { KvStore } from " @fedify/fedify" ;
361+ // ---cut-before---
362+ import { createFederation } from " @fedify/fedify" ;
363+ import { MysqlMessageQueue } from " @fedify/mysql" ;
364+ import mysql from " mysql2/promise" ;
365+
366+ const pool = mysql .createPool (" mysql://user:pass@localhost/db" );
367+ const federation = createFederation <void >({
368+ // ---cut-start---
369+ kv: null as unknown as KvStore ,
370+ // ---cut-end---
371+ queue: new MysqlMessageQueue (pool ), // [!code highlight]
372+ // ... other options
373+ });
374+ ~~~~
375+
376+ [ `MysqlMessageQueue` ] : https://jsr.io/@fedify/mysql/doc/mq/~/MysqlMessageQueue
377+
296378### ` SqliteMessageQueue `
297379
298380* This API is available since Fedify 2.0.0.*
@@ -767,6 +849,9 @@ The following implementations do not yet support native retry:
767849[ ` PostgresMessageQueue ` ]
768850: Native retry support planned for future release.
769851
852+ [ ` MysqlMessageQueue ` ]
853+ : No native retry support (` ~MessageQueue.nativeRetrial ` is ` false ` ).
854+
770855[ ` AmqpMessageQueue ` ]
771856: Native retry support planned for future release.
772857
@@ -835,6 +920,7 @@ The following implementations support ordering keys:
835920| [ ` DenoKvMessageQueue ` ] | Yes |
836921| [ ` RedisMessageQueue ` ] | Yes |
837922| [ ` PostgresMessageQueue ` ] | Yes |
923+ | [ ` MysqlMessageQueue ` ] | Yes |
838924| [ ` AmqpMessageQueue ` ] | Yes[ ^ 1 ] |
839925| [ ` SqliteMessageQueue ` ] | Yes |
840926| ` WorkersMessageQueue ` | Yes[ ^ 2 ] |
0 commit comments