Skip to content

Commit a7c236c

Browse files
committed
Add topic-based routing system with AMQP-style patterns and validation functions.
1 parent d024183 commit a7c236c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

sqlx4k-postgres-pgmq/src/sql/topics.sql

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,48 @@ COMMENT ON FUNCTION pgmq.send_topic(text, jsonb, jsonb, integer) IS
435435
'Transaction is atomic - either all matching queues receive the message or none do. '
436436
'Usage: SELECT pgmq.send_topic(''logs.error'', ''{"message": "error occurred"}''::jsonb, NULL, 0);';
437437

438+
-- ============================================================================
439+
-- Send Topic Overload Functions
440+
-- ============================================================================
441+
-- Convenience overloads with fewer parameters
442+
-- ============================================================================
443+
444+
-- Overload: send_topic(routing_key, msg)
445+
DROP FUNCTION IF EXISTS pgmq.send_topic(text, jsonb);
446+
CREATE OR REPLACE FUNCTION pgmq.send_topic(routing_key text, msg jsonb)
447+
RETURNS integer
448+
LANGUAGE plpgsql
449+
VOLATILE
450+
AS $$
451+
BEGIN
452+
-- Delegate to the main send_topic function with default values
453+
RETURN pgmq.send_topic(routing_key, msg, NULL, 0);
454+
END;
455+
$$;
456+
457+
COMMENT ON FUNCTION pgmq.send_topic(text, jsonb) IS
458+
'Convenience overload for send_topic with default headers (NULL) and delay (0). '
459+
'Sends a message to all queues that match the routing key pattern. '
460+
'Usage: SELECT pgmq.send_topic(''logs.error'', ''{"message": "error"}''::jsonb);';
461+
462+
-- Overload: send_topic(routing_key, msg, delay)
463+
DROP FUNCTION IF EXISTS pgmq.send_topic(text, jsonb, integer);
464+
CREATE OR REPLACE FUNCTION pgmq.send_topic(routing_key text, msg jsonb, delay integer)
465+
RETURNS integer
466+
LANGUAGE plpgsql
467+
VOLATILE
468+
AS $$
469+
BEGIN
470+
-- Delegate to the main send_topic function with default headers
471+
RETURN pgmq.send_topic(routing_key, msg, NULL, delay);
472+
END;
473+
$$;
474+
475+
COMMENT ON FUNCTION pgmq.send_topic(text, jsonb, integer) IS
476+
'Convenience overload for send_topic with default headers (NULL). '
477+
'Sends a message to all queues that match the routing key pattern with a specified delay. '
478+
'Usage: SELECT pgmq.send_topic(''logs.error'', ''{"message": "error"}''::jsonb, 60);';
479+
438480

439481
-- ========================================================================
440482
-- Usage Examples

0 commit comments

Comments
 (0)