-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SD-103813 | implementation of the SQS receive message #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ package inssqs | |||||||||||
|
||||||||||||
import ( | ||||||||||||
"context" | ||||||||||||
"fmt" | ||||||||||||
"github.com/aws/aws-sdk-go-v2/aws" | ||||||||||||
"github.com/aws/aws-sdk-go-v2/aws/retry" | ||||||||||||
awsconfig "github.com/aws/aws-sdk-go-v2/config" | ||||||||||||
|
@@ -18,6 +19,7 @@ import ( | |||||||||||
type Interface interface { | ||||||||||||
SendMessageBatch(entries []SQSMessageEntry) (failed []SQSMessageEntry, err error) | ||||||||||||
DeleteMessageBatch(entries []SQSDeleteMessageEntry) (failed []SQSDeleteMessageEntry, err error) | ||||||||||||
ReceiveMessageBatch(rmi ReceiveMessageInput) (ReceiveMessageOutput, error) | ||||||||||||
} | ||||||||||||
|
||||||||||||
type queue struct { | ||||||||||||
|
@@ -117,6 +119,42 @@ func (c *Config) setDefaults() { | |||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
// ReceiveMessageBatch receives a batch of messages from an SQS queue | ||||||||||||
// | ||||||||||||
// Parameters: | ||||||||||||
// - rmi: ReceiveMessageInput containing the parameters for receiving messages from the SQS queue. | ||||||||||||
// | ||||||||||||
// Returns: | ||||||||||||
// - res: A pointer to ReceiveMessageOutput containing the received messages. | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't return the pointer |
||||||||||||
// - err: An error indicating any failure during the receiving process, nil if all messages were received successfully. | ||||||||||||
func (q *queue) ReceiveMessageBatch(rmi ReceiveMessageInput) (ReceiveMessageOutput, error) { | ||||||||||||
if rmi.MaxNumberOfMessages > 10 { | ||||||||||||
return ReceiveMessageOutput{}, fmt.Errorf("maxMessages should be less than or equal to 10") | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fmt.Errorf is redundant here, formating isn't used. we can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
} | ||||||||||||
|
||||||||||||
if rmi.MaxNumberOfMessages < 1 { | ||||||||||||
return ReceiveMessageOutput{}, fmt.Errorf("maxMessages should be greater than 0") | ||||||||||||
} | ||||||||||||
|
||||||||||||
input := &awssqs.ReceiveMessageInput{ | ||||||||||||
QueueUrl: q.url, | ||||||||||||
MaxNumberOfMessages: rmi.MaxNumberOfMessages, | ||||||||||||
VisibilityTimeout: rmi.VisibilityTimeout, | ||||||||||||
AttributeNames: rmi.AttributeNames, | ||||||||||||
MessageAttributeNames: rmi.MessageAttributeNames, | ||||||||||||
ReceiveRequestAttemptId: rmi.ReceiveRequestAttemptId, | ||||||||||||
WaitTimeSeconds: rmi.WaitTimeSeconds, | ||||||||||||
} | ||||||||||||
|
||||||||||||
res, err := q.client.ReceiveMessage(context.Background(), input) | ||||||||||||
|
||||||||||||
if err != nil { | ||||||||||||
Comment on lines
+149
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
in styling-wise, we prefer handling error directly with no new line between |
||||||||||||
return ReceiveMessageOutput{}, err | ||||||||||||
} | ||||||||||||
|
||||||||||||
return ReceiveMessageOutput{Messages: res.Messages}, nil | ||||||||||||
} | ||||||||||||
|
||||||||||||
// SendMessageBatch sends a batch of messages to an SQS queue, handling retries and respecting batch size constraints. | ||||||||||||
// | ||||||||||||
// Parameters: | ||||||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code example below would be nice like examples above