feat(queue-url): ExternalURLBase для публичного QueueUrl (+ env SHARED_SQS_EXTERNAL_URL_BASE), тест
This commit is contained in:
@@ -67,6 +67,11 @@ func LoadYamlConfig(filename string, env string) []string {
|
||||
|
||||
models.CurrentEnvironment = envs[env]
|
||||
|
||||
// Публичный адрес очередей (напр. https://sqs.sinefo.ru) — override через env.
|
||||
if v := os.Getenv("SHARED_SQS_EXTERNAL_URL_BASE"); v != "" {
|
||||
models.CurrentEnvironment.ExternalURLBase = v
|
||||
}
|
||||
|
||||
if envs[env].Port != "" {
|
||||
ports = []string{envs[env].Port}
|
||||
}
|
||||
@@ -90,6 +95,9 @@ func LoadYamlConfig(filename string, env string) []string {
|
||||
queueUrl = "http://" + models.CurrentEnvironment.Region + "." + models.CurrentEnvironment.Host + ":" +
|
||||
models.CurrentEnvironment.Port + "/" + models.CurrentEnvironment.AccountID + "/" + queue.Name
|
||||
}
|
||||
if base := strings.TrimRight(models.CurrentEnvironment.ExternalURLBase, "/"); base != "" {
|
||||
queueUrl = base + "/" + models.CurrentEnvironment.AccountID + "/" + queue.Name
|
||||
}
|
||||
queueArn := "arn:aws:sqs:" + models.CurrentEnvironment.Region + ":" + models.CurrentEnvironment.AccountID + ":" + queue.Name
|
||||
|
||||
if queue.ReceiveMessageWaitTimeSeconds == 0 {
|
||||
|
||||
@@ -4,6 +4,7 @@ Local: # Environment name that can be passed on the
|
||||
Port: 4100 # port to listen on.
|
||||
Region: us-east-1
|
||||
AccountId: "100010001000"
|
||||
ExternalURLBase: "" # публичный адрес очередей (напр. https://sqs.sinefo.ru); пусто → http://{region}.{host}:{port}
|
||||
LogToFile: false # Log messages (true/false)
|
||||
LogFile: .st/goaws_messages.log # Log filename (for message logging
|
||||
EnableDuplicates: false # Enable or not deduplication based on messageDeduplicationId
|
||||
|
||||
@@ -5,6 +5,7 @@ package gosqs
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"shared-sqs/app/auth"
|
||||
"shared-sqs/app/models"
|
||||
@@ -27,6 +28,10 @@ return t
|
||||
// tenantQueueURL — формирует URL очереди для тенанта.
|
||||
// Ловушка #10: QueueUrl ОБЯЗАН содержать tenantID в пути, иначе AWS SDK не сможет send/receive.
|
||||
func tenantQueueURL(t *tenant.Tenant, queueName string) string {
|
||||
// Публичный адрес (напр. https://sqs.sinefo.ru) — приоритетнее локального формата.
|
||||
if base := strings.TrimRight(models.CurrentEnvironment.ExternalURLBase, "/"); base != "" {
|
||||
return base + "/" + t.ID + "/" + queueName
|
||||
}
|
||||
host := models.CurrentEnvironment.Host
|
||||
port := models.CurrentEnvironment.Port
|
||||
region := models.CurrentEnvironment.Region
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package gosqs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"shared-sqs/app/models"
|
||||
"shared-sqs/app/tenant"
|
||||
)
|
||||
|
||||
// TestTenantQueueURL — проверяет формирование QueueUrl: публичный ExternalURLBase
|
||||
// приоритетнее локального формата, пустое значение даёт старый формат.
|
||||
func TestTenantQueueURL(t *testing.T) {
|
||||
old := models.CurrentEnvironment
|
||||
defer func() { models.CurrentEnvironment = old }()
|
||||
|
||||
tt := &tenant.Tenant{ID: "t-abc123"}
|
||||
|
||||
// Публичный адрес; хвостовой слеш обрезается.
|
||||
models.CurrentEnvironment = models.Environment{ExternalURLBase: "https://sqs.sinefo.ru/"}
|
||||
if got, want := tenantQueueURL(tt, "orders"), "https://sqs.sinefo.ru/t-abc123/orders"; got != want {
|
||||
t.Fatalf("external base: got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
// Пусто → старый формат с region.
|
||||
models.CurrentEnvironment = models.Environment{Host: "goaws.com", Port: "4100", Region: "us-east-1"}
|
||||
if got, want := tenantQueueURL(tt, "orders"), "http://us-east-1.goaws.com:4100/t-abc123/orders"; got != want {
|
||||
t.Fatalf("local format (region): got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
// Пусто, без region.
|
||||
models.CurrentEnvironment = models.Environment{Host: "localhost", Port: "4100"}
|
||||
if got, want := tenantQueueURL(tt, "orders"), "http://localhost:4100/t-abc123/orders"; got != want {
|
||||
t.Fatalf("local format (no region): got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ Port string
|
||||
SqsPort string
|
||||
Region string
|
||||
AccountID string
|
||||
ExternalURLBase string
|
||||
LogToFile bool
|
||||
LogFile string
|
||||
EnableDuplicates bool
|
||||
|
||||
Reference in New Issue
Block a user