feat(queue): add message-plane core logic for send/receive/delete/visibility
Implements SendMessage (size cap, FIFO dedup, shard routing), ReceiveMessage (long-poll loop across active+closing shards, FIFO per-group exclusivity gating, redelivery hand-out), DeleteMessage (ack + low-watermark offset advancement), and ChangeMessageVisibility against the Redis state layer and a real Kafka producer/consumer.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
goredis "github.com/redis/go-redis/v9"
|
||||
|
||||
kmsvcredis "github.com/rockliang/kafka-management-service/internal/redis"
|
||||
)
|
||||
|
||||
// acquireFIFOSlot claims the per-group exclusivity gate (design.md §3) so
|
||||
// ReceiveMessage never hands out two in-flight messages for the same
|
||||
// MessageGroupId at once. The lock's TTL matches the message's own
|
||||
// visibility timeout, so a lock left by a crashed/timed-out consumer
|
||||
// self-heals on the same schedule the reaper uses (design.md §5) — it is
|
||||
// also released early, by ack.lua/reap.lua, on ack/redeliver/DLQ-route.
|
||||
func acquireFIFOSlot(ctx context.Context, rdb *goredis.Client, queueName, groupID, receiptHandle string, visibilityTimeout time.Duration) (bool, error) {
|
||||
ok, err := kmsvcredis.AcquireFIFOLock(ctx, rdb, queueName, groupID, receiptHandle, visibilityTimeout)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("acquire fifo slot %s/%s: %w", queueName, groupID, err)
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
Reference in New Issue
Block a user