Skip to content

Commit

Permalink
[sqs] Add single msg sending (#74)
Browse files Browse the repository at this point in the history
* Add support for sending a single message directly to SQS

* Cleaned up extra whitespace

Co-authored-by: Michael Gale <[email protected]>
  • Loading branch information
mgale and Michael Gale authored Oct 15, 2020
1 parent 4e336ec commit 57df983
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sqs/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ func (q *Queue) send(msg []*SDK.SendMessageBatchRequestEntry) error {
return err
}

// SendSingleMessage sends a message directly to the SQS immediately
// and bypasses the spool and batch submits.
func (q *Queue) SendSingleMessage(message string) (string, error) {
res, err := q.service.client.SendMessage(&SDK.SendMessageInput{
MessageBody: pointers.String(message),
QueueUrl: q.url,
})
return res.GoString(), err
}

// Fetch fetches message list from the queue with limit.
func (q *Queue) Fetch(num int) ([]*Message, error) {
wait := q.waitTimeSeconds
Expand Down
10 changes: 10 additions & 0 deletions sqs/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ func TestSend(t *testing.T) {
assert.Nil(err)
}

func TestSendSingleMessage(t *testing.T) {
assert := assert.New(t)
svc := getTestClient(t)
q, _ := svc.GetQueue("test")

result, err := q.SendSingleMessage("foo sending single message")
assert.NotNil(result)
assert.Nil(err)
}

func TestFetch(t *testing.T) {
assert := assert.New(t)
svc := getTestClient(t)
Expand Down

0 comments on commit 57df983

Please sign in to comment.