Files
query-orchestration/internal/serviceconfig/queue/send.go
T

40 lines
835 B
Go
Raw Normal View History

package queue
import (
"context"
"encoding/json"
"log/slog"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sqs"
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
)
type SendParams struct {
QueueURL string
Body interface{}
Attributes map[string]types.MessageAttributeValue
}
func (c *QueueConfig) SendToQueue(ctx context.Context, params *SendParams) error {
jsonBytes, err := json.Marshal(params.Body)
if err != nil {
return err
}
strBody := string(jsonBytes)
slog.Debug("sending to queue", "url", params.QueueURL, "body", strBody)
_, err = c.QueueClient.SendMessage(ctx, &sqs.SendMessageInput{
MessageAttributes: params.Attributes,
QueueUrl: aws.String(params.QueueURL),
MessageBody: aws.String(strBody),
})
if err != nil {
return err
}
return nil
}