Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.22
ARG GO_VERSION=1.23
FROM golang:${GO_VERSION}-bookworm as builder

WORKDIR /usr/src/app
Expand Down
10 changes: 10 additions & 0 deletions cmd/smoothmq/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/poundifdef/smoothmq/dashboard"
"github.com/poundifdef/smoothmq/models"
"github.com/poundifdef/smoothmq/protocols/sqs"
"github.com/poundifdef/smoothmq/queue/pgmq"
"github.com/poundifdef/smoothmq/queue/sqlite"
"github.com/poundifdef/smoothmq/tenants/defaultmanager"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -53,6 +54,15 @@ func Run(tm models.TenantManager, queue models.Queue, cfg config.ServerCommand)
tm = defaultmanager.NewDefaultTenantManager(cfg.SQS.Keys)
}

// Initialize PGMQ when configured
if queue == nil && cfg.PGMQ.Uri != "" {
_queue, err := pgmq.NewPGMQQueue(cfg.PGMQ)
if err != nil {
panic(err)
}
queue = _queue
}

// Initialize default queue implementation
if queue == nil {
queue = sqlite.NewSQLiteQueue(cfg.SQLite)
Expand Down
72 changes: 66 additions & 6 deletions cmd/smoothmq/tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
func Run(c smoothCfg.TesterCommand) {
var sentMessages, receivedMessages int

queueUrl := "https://sqs.us-east-1.amazonaws.com/123/test-queue"

// Load the AWS configuration with hardcoded credentials
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion("us-east-1"),
Expand All @@ -41,7 +39,9 @@ func Run(c smoothCfg.TesterCommand) {

var wg sync.WaitGroup

var ch chan int
ch := make(chan int)

queueUrl := createQueue(sqsClient)

for i := 0; i < c.Senders; i++ {
wg.Add(1)
Expand Down Expand Up @@ -71,6 +71,10 @@ func Run(c smoothCfg.TesterCommand) {
pct = float64(receivedMessages) / float64(sentMessages)
}
log.Info().Msg(fmt.Sprintf("sent: %d, received: %d, pct: %f", sentMessages, receivedMessages, pct))
if (sentMessages > 0 && sentMessages == receivedMessages) {
close(ch)
return
}
time.Sleep(1 * time.Second)
}
}()
Expand All @@ -79,12 +83,15 @@ func Run(c smoothCfg.TesterCommand) {

if c.Senders > 0 {
log.Info().Msg("All messages sent")
if c.Receivers == 0 {
os.Exit(0)
}
}

<-ch

// Test changing message visibility timeout
queueUrl2 := createQueue(sqsClient)
log.Info().Msgf("queue2: %s", queueUrl)
testChangeMessageVisibility(sqsClient, queueUrl2)
os.Exit(0)
}

func GenerateRandomString(n int) string {
Expand All @@ -96,6 +103,18 @@ func GenerateRandomString(n int) string {
return string(b)
}

func createQueue(client *sqs.Client) string {
queueName := fmt.Sprintf("test-queue-%d", rand.Int())
i := &sqs.CreateQueueInput{
QueueName: &queueName,
}
result, err := client.CreateQueue(context.TODO(), i)
if err != nil {
log.Error().Err(err).Send()
}
return *result.QueueUrl
}

func sendMessage(client *sqs.Client, queueUrl string, goroutineID, requestID, batchSize, delaySeconds int) {

if batchSize > 1 {
Expand Down Expand Up @@ -154,6 +173,47 @@ func sendMessage(client *sqs.Client, queueUrl string, goroutineID, requestID, ba
// time.Sleep(100 * time.Millisecond)
}

func testChangeMessageVisibility(client *sqs.Client, queueUrl string) {
log.Info().Msg("Testing ChangeMessageVisibility")
// Send a message
messageBody := "Test message for visibility timeout"
sendMessageInput := &sqs.SendMessageInput{
QueueUrl: &queueUrl,
MessageBody: &messageBody,
}
sendMessageOutput, err := client.SendMessage(context.TODO(), sendMessageInput)
if err != nil {
log.Fatal().Msgf("failed to send message, %v", err)
}

for {
recvMsg := &sqs.ReceiveMessageInput{
QueueUrl: aws.String(queueUrl),
MaxNumberOfMessages: 1,
}
msgs, err := client.ReceiveMessage(context.TODO(), recvMsg)
if err != nil {
log.Error().Err(err).Send()
}
if len(msgs.Messages) == 1 {
break
}
}

// Change the visibility timeout
changeVisibilityInput := &sqs.ChangeMessageVisibilityInput{
QueueUrl: &queueUrl,
ReceiptHandle: sendMessageOutput.MessageId,
VisibilityTimeout: 60,
}
_, err = client.ChangeMessageVisibility(context.TODO(), changeVisibilityInput)
if err != nil {
log.Fatal().Msgf("failed to change message visibility timeout, %v", err)
}

log.Info().Msg("Successfully changed message visibility timeout")
}

func receiveMessage(client *sqs.Client, queueUrl string, goroutineID int) int {
i := &sqs.ReceiveMessageInput{
QueueUrl: aws.String(queueUrl),
Expand Down
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ServerCommand struct {
SQS SQSConfig `embed:"" prefix:"sqs-" envprefix:"Q_SQS_"`
Dashboard DashboardConfig `embed:"" prefix:"dashboard-" envprefix:"Q_DASHBOARD_"`
SQLite SQLiteConfig `embed:"" prefix:"sqlite-" envprefix:"Q_SQLITE_"`
PGMQ PGMQConfig `embed:"" prefix:"pgmq-" envprefix:"Q_PGMQ_"`
Metrics MetricsConfig `embed:"" prefix:"metrics-" name:"metrics" envprefix:"Q_METRICS_"`

DisableTelemetry bool `name:"disable-telemetry" default:"false" env:"DISABLE_TELEMETRY"`
Expand All @@ -55,6 +56,10 @@ type SQLiteConfig struct {
Path string `name:"path" help:"Path of SQLite file" default:"smoothmq.sqlite" env:"PATH"`
}

type PGMQConfig struct {
Uri string `name:"uri" help:"PostgreSQL connection string" env:"URI"`
}

type SQSConfig struct {
Enabled bool `name:"enabled" default:"true" help:"Enable SQS protocol for queue" env:"ENABLED"`
Host string `name:"host" default:"localhost" help:"hostname or ip address for SQS protocol" env:"HOST"`
Expand Down
73 changes: 65 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/poundifdef/smoothmq

go 1.22.2
go 1.23.0

toolchain go1.23.5

require (
github.com/alecthomas/kong v0.9.0
Expand All @@ -10,20 +12,27 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.17.23
github.com/aws/aws-sdk-go-v2/service/sqs v1.34.1
github.com/bwmarrin/snowflake v0.3.0
github.com/craigpastro/pgmq-go v0.6.0
github.com/gofiber/contrib/fiberzerolog v1.0.1
github.com/gofiber/fiber/v2 v2.52.5
github.com/gofiber/template/html/v2 v2.1.1
github.com/jackc/pgtype v1.14.3
github.com/mattn/go-sqlite3 v1.14.22
github.com/prometheus/client_golang v1.19.1
github.com/rs/zerolog v1.33.0
github.com/tidwall/gjson v1.17.1
github.com/valyala/fasthttp v1.51.0
gorm.io/driver/postgres v1.5.9
gorm.io/driver/sqlite v1.5.6
gorm.io/gorm v1.25.11
)

require (
dario.cat/mergo v1.0.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/avast/retry-go/v4 v4.6.1 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13 // indirect
Expand All @@ -35,28 +44,76 @@ require (
github.com/aws/aws-sdk-go-v2/service/sts v1.30.1 // indirect
github.com/aws/smithy-go v1.20.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v28.0.4+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/ebitengine/purego v0.8.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/gofiber/template v1.8.3 // indirect
github.com/gofiber/utils v1.1.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.4 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35 // indirect
github.com/magiconair/properties v1.8.10 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.6.0 // indirect
github.com/moby/sys/user v0.4.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/shirou/gopsutil/v4 v4.25.3 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/testcontainers/testcontainers-go v0.36.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.15 // indirect
github.com/tklauser/numcpus v0.10.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading