feat: монолит iot-service (Фаза 1) — config/store/api/bridge/consumer без k8s, устройства в PG, новые Dockerfile/Makefile
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// Package sqsclient — общий фабричный клиент shared-SQS для монолита.
|
||||
//
|
||||
// Используют: bridge (SendMessage), consumer (ReceiveMessage/DeleteMessage),
|
||||
// admin-stats (GetQueueUrl/GetQueueAttributes).
|
||||
package sqsclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
|
||||
"gitea.services.ngcloud.ru/Nail/IoT/internal/service/config"
|
||||
)
|
||||
|
||||
// New создаёт SQS-клиент с переопределённым endpoint (self-hosted shared-sqs).
|
||||
func New(cfg *config.Config) *sqs.Client {
|
||||
return sqs.New(sqs.Options{
|
||||
Region: cfg.SQSRegion,
|
||||
Credentials: credentials.NewStaticCredentialsProvider(
|
||||
cfg.SQSAccessKey, cfg.SQSSecretKey, "",
|
||||
),
|
||||
BaseEndpoint: aws.String(cfg.SQSEndpoint),
|
||||
})
|
||||
}
|
||||
|
||||
// ResolveQueueURL получает URL очереди по имени (один вызов при старте).
|
||||
func ResolveQueueURL(ctx context.Context, client *sqs.Client, queueName string) (string, error) {
|
||||
out, err := client.GetQueueUrl(ctx, &sqs.GetQueueUrlInput{
|
||||
QueueName: aws.String(queueName),
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("sqs: GetQueueUrl %q: %w", queueName, err)
|
||||
}
|
||||
return aws.ToString(out.QueueUrl), nil
|
||||
}
|
||||
Reference in New Issue
Block a user