Skip to content

feat(sql/queue): merge DLQ logic into message table#34

Merged
behinddwalls merged 1 commit into
mainfrom
preetam/sql-queue-refactor
Feb 21, 2026
Merged

feat(sql/queue): merge DLQ logic into message table#34
behinddwalls merged 1 commit into
mainfrom
preetam/sql-queue-refactor

Conversation

@behinddwalls
Copy link
Copy Markdown
Collaborator

@behinddwalls behinddwalls commented Feb 20, 2026

Summary

Why?
Previously, DLQ messages were stored in a separate queue_dlq table,
requiring separate schema management and limiting the ability to
consume from DLQ topics. By merging DLQ into the messages table with
a topic suffix pattern (e.g., "orders" → "orders_dlq"), we can:

  • Reuse existing subscriber/publisher logic for DLQ consumption
  • Simplify schema management (single table)
  • Track DLQ-specific metadata (failure_count, last_error, etc.)
  • Enable DLQ reprocessing workflows

What?

  • Add TopicSuffix to DLQConfig (default "_dlq")
  • Add DLQ columns to queue_messages schema (failed_at, failure_count,
    last_error, original_topic) as nullable fields
  • Update MoveToDLQ to insert into queue_messages with DLQ topic name
  • Expose DLQ metadata through delivery metadata for testing
  • Remove separate queue_dlq.sql schema
  • Update FetchByOffset to select and populate DLQ fields
  • Fix unit test mocks to include all 11 columns
  • Document retry_count vs failure_count distinction in schema

Test Plan

Issues

Stack

  1. @ feat(sql/queue): merge DLQ logic into message table #34
  2. test(queue/sql): add comprehensive e2e integration tests #35

behinddwalls added a commit that referenced this pull request Feb 20, 2026
## Summary
### Why?
Need Publisher implementation to enable message publishing to SQL queue
topics.

### What?

- Publisher validates topic names and publishes single messages via
MessageStore
- Thread-safe with RWMutex for concurrent publish calls
- Idempotent Close() operation
- Comprehensive test coverage for publish, validation, metrics, and
concurrency

- Single and multiple message publishing tested
- Invalid topic names rejected (uppercase, special chars, empty)
- Publisher closed state prevents further publishes
- Concurrent publish operations verified thread-safe
- Context cancellation handled correctly

## Test Plan
make test

## Issues


## Stack
1. @ #22
1. #23
1. #21
1. #24
1. #34
@behinddwalls behinddwalls force-pushed the sql-queue-integration branch 3 times, most recently from ff9f23e to 0e6c4cc Compare February 20, 2026 22:57
@behinddwalls behinddwalls force-pushed the preetam/sql-queue-refactor branch from afee107 to 4cfb4c5 Compare February 20, 2026 23:09
@behinddwalls behinddwalls marked this pull request as ready for review February 20, 2026 23:09
@behinddwalls behinddwalls requested review from a team and sbalabanov as code owners February 20, 2026 23:09
behinddwalls added a commit that referenced this pull request Feb 20, 2026
## Summary
## Why?
Need to integrate publisher and subscriber with Queue factory interface
and provide comprehensive documentation and end-to-end testing.

## What?
- Factory creates publisher and subscriber singletons with lifecycle
management
- Comprehensive README with usage examples and architecture docs

## Test Plan


## Issues


## Stack
1. @ #24
1. #34
1. #35
Comment thread extensions/queue/sql/schema/queue_messages.sql Outdated
Comment thread extensions/queue/sql/publisher.go Outdated
Why?
Previously, DLQ messages were stored in a separate queue_dlq table,
requiring separate schema management and limiting the ability to
consume from DLQ topics. By merging DLQ into the messages table with
a topic suffix pattern (e.g., "orders" → "orders_dlq"), we can:
- Reuse existing subscriber/publisher logic for DLQ consumption
- Simplify schema management (single table)
- Track DLQ-specific metadata (failure_count, last_error, etc.)
- Enable DLQ reprocessing workflows

What?
- Add TopicSuffix to DLQConfig (default "_dlq")
- Add DLQ columns to queue_messages schema (failed_at, failure_count,
  last_error, original_topic) as nullable fields
- Update MoveToDLQ to insert into queue_messages with DLQ topic name
- Expose DLQ metadata through delivery metadata for testing
- Remove separate queue_dlq.sql schema
- Update FetchByOffset to select and populate DLQ fields
- Fix unit test mocks to include all 11 columns
- Document retry_count vs failure_count distinction in schema

Co-Authored-By: Preetam Dwivedi <preetam@uber.com>

refactor(queue/sql): use sentinel values instead of nullable DLQ fields

Use 0 for int64/int and empty string for string fields instead of
pointers. This simplifies the code and follows Go best practices.

Changes:
- messageRow: FailedAt, FailureCount, LastError, OriginalTopic now non-pointer
- Schema: DLQ fields NOT NULL (no DEFAULT in schema, set in app code)
- Insert: explicitly set DLQ fields to 0/"" for normal messages
- FetchByOffset: scan into regular types (0/"" for normal messages)
- Subscriber: check > 0 or != "" instead of != nil
- Tests: mock with 0/"" instead of nil

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@behinddwalls behinddwalls force-pushed the preetam/sql-queue-refactor branch from 4cfb4c5 to fca4ddc Compare February 20, 2026 23:57
@behinddwalls behinddwalls changed the base branch from sql-queue-integration to main February 20, 2026 23:57
@behinddwalls behinddwalls merged commit 462f8e4 into main Feb 21, 2026
1 check passed
@behinddwalls behinddwalls deleted the preetam/sql-queue-refactor branch February 21, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants