2024-12-18 18:54:48 +00:00
|
|
|
package queue
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
|
|
"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"
|
|
|
|
|
)
|
|
|
|
|
|
2025-01-10 11:12:03 +00:00
|
|
|
func Send(ctx context.Context, config *Config, body interface{}, attributes map[string]types.MessageAttributeValue) error {
|
2024-12-18 18:54:48 +00:00
|
|
|
jsonBytes, err := json.Marshal(body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strBody := string(jsonBytes)
|
|
|
|
|
|
|
|
|
|
_, err = config.Client.SendMessage(ctx, &sqs.SendMessageInput{
|
2025-01-10 11:12:03 +00:00
|
|
|
MessageAttributes: attributes,
|
|
|
|
|
QueueUrl: aws.String(config.URL),
|
|
|
|
|
MessageBody: aws.String(strBody),
|
2024-12-18 18:54:48 +00:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|