putting in base query and collector framework
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
)
|
||||
|
||||
type QueueConfig struct {
|
||||
URL string
|
||||
Client *sqs.Client
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func Delete(ctx context.Context, config *QueueConfig, msg *types.Message) error {
|
||||
_, err := config.Client.DeleteMessage(ctx, &sqs.DeleteMessageInput{
|
||||
QueueUrl: aws.String(config.URL),
|
||||
ReceiptHandle: msg.ReceiptHandle,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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"
|
||||
)
|
||||
|
||||
func Send(ctx context.Context, config *QueueConfig, typeName string, body interface{}) error {
|
||||
jsonBytes, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
strBody := string(jsonBytes)
|
||||
|
||||
_, err = config.Client.SendMessage(ctx, &sqs.SendMessageInput{
|
||||
MessageAttributes: map[string]types.MessageAttributeValue{
|
||||
"type": {
|
||||
DataType: aws.String("String"),
|
||||
StringValue: aws.String(typeName),
|
||||
},
|
||||
},
|
||||
QueueUrl: aws.String(config.URL),
|
||||
MessageBody: aws.String(strBody),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user