Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
a590e76d
Commit
a590e76d
authored
3 years ago
by
Johan de Klerk
Browse files
Options
Downloads
Patches
Plain Diff
#24
: Added more info to SQS messenger
parent
88de2e49
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!19
Resolve "Upload large SQS messages to S3"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
sqs/sqs.go
+14
-21
14 additions, 21 deletions
sqs/sqs.go
with
14 additions
and
21 deletions
sqs/sqs.go
+
14
−
21
View file @
a590e76d
...
...
@@ -8,6 +8,7 @@ import (
"fmt"
"github.com/google/uuid"
"gitlab.com/uafrica/go-utils/s3"
"gitlab.com/uafrica/go-utils/string_utils"
"io/ioutil"
"time"
...
...
@@ -28,6 +29,8 @@ type Messenger struct {
Region
string
S3Session
*
s3
.
SessionWithHelpers
S3BucketName
string
MessageGroupID
*
string
RequestIDHeaderKey
string
}
// NewSQSClient constructs a Messenger which sends messages to an SQS queue
...
...
@@ -54,12 +57,7 @@ func NewSQSClient(awsRegion string) (*sqs.SQS, error) {
// SendSQSMessage sends a message to the queue associated with the messenger
// headers - string message attributes of the SQS message (see AWS SQS documentation)
// body - body of the SQS message (see AWS SQS documentation)
func
(
m
*
Messenger
)
SendSQSMessage
(
headers
map
[
string
]
string
,
body
string
,
currentRequestID
*
string
,
sqsType
string
,
headerKey
string
,
messageGroupID
...
string
)
(
string
,
error
)
{
msgGrpID
:=
""
if
len
(
messageGroupID
)
>
0
&&
messageGroupID
[
0
]
!=
""
{
msgGrpID
=
messageGroupID
[
0
]
}
func
(
m
*
Messenger
)
SendSQSMessage
(
headers
map
[
string
]
string
,
body
string
,
currentRequestID
*
string
,
sqsType
string
)
(
string
,
error
)
{
msgAttrs
:=
make
(
map
[
string
]
*
sqs
.
MessageAttributeValue
)
for
key
,
val
:=
range
headers
{
...
...
@@ -71,7 +69,7 @@ func (m *Messenger) SendSQSMessage(headers map[string]string, body string, curre
// Add request ID
if
currentRequestID
!=
nil
{
msgAttrs
[
h
eaderKey
]
=
&
sqs
.
MessageAttributeValue
{
msgAttrs
[
m
.
RequestIDH
eaderKey
]
=
&
sqs
.
MessageAttributeValue
{
DataType
:
aws
.
String
(
"String"
),
StringValue
:
aws
.
String
(
*
currentRequestID
),
}
...
...
@@ -84,7 +82,7 @@ func (m *Messenger) SendSQSMessage(headers map[string]string, body string, curre
var
res
*
sqs
.
SendMessageOutput
var
err
error
if
msgGr
pID
==
""
{
if
string_utils
.
UnwrapString
(
m
.
MessageGrou
pID
)
==
""
{
res
,
err
=
sqsClient
.
SendMessage
(
&
sqs
.
SendMessageInput
{
MessageAttributes
:
msgAttrs
,
MessageBody
:
aws
.
String
(
body
),
...
...
@@ -95,7 +93,7 @@ func (m *Messenger) SendSQSMessage(headers map[string]string, body string, curre
MessageAttributes
:
msgAttrs
,
MessageBody
:
aws
.
String
(
body
),
QueueUrl
:
&
m
.
QueueURL
,
MessageGroupId
:
&
msgGr
pID
,
MessageGroupId
:
m
.
MessageGrou
pID
,
})
}
...
...
@@ -106,12 +104,7 @@ func (m *Messenger) SendSQSMessage(headers map[string]string, body string, curre
return
*
res
.
MessageId
,
err
}
func
SendSQSMessage
(
msgr
Messenger
,
objectToSend
interface
{},
currentRequestID
*
string
,
sqsType
string
,
headerKey
string
,
messageGroupID
...
string
)
error
{
msgGrpID
:=
""
if
len
(
messageGroupID
)
>
0
&&
messageGroupID
[
0
]
!=
""
{
msgGrpID
=
messageGroupID
[
0
]
}
func
SendSQSMessage
(
msgr
Messenger
,
objectToSend
interface
{},
currentRequestID
*
string
,
sqsType
string
)
error
{
if
sqsClient
==
nil
{
var
err
error
sqsClient
,
err
=
NewSQSClient
(
msgr
.
Region
)
...
...
@@ -145,7 +138,7 @@ func SendSQSMessage(msgr Messenger, objectToSend interface{}, currentRequestID *
}
}
msgID
,
err
:=
msgr
.
SendSQSMessage
(
headers
,
message
,
currentRequestID
,
sqsType
,
headerKey
,
msgGrpID
)
msgID
,
err
:=
msgr
.
SendSQSMessage
(
headers
,
message
,
currentRequestID
,
sqsType
)
if
err
!=
nil
{
logs
.
ErrorWithMsg
(
"Failed to send sqs event"
,
err
)
return
err
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment