From 57df98331c59e948514d979e6dff8ca2c1e86b39 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Oct 2020 21:18:08 -0600 Subject: [PATCH] [sqs] Add single msg sending (#74) * Add support for sending a single message directly to SQS * Cleaned up extra whitespace Co-authored-by: Michael Gale --- sqs/queue.go | 10 ++++++++++ sqs/queue_test.go | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/sqs/queue.go b/sqs/queue.go index 6559b02..ea1024a 100644 --- a/sqs/queue.go +++ b/sqs/queue.go @@ -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 diff --git a/sqs/queue_test.go b/sqs/queue_test.go index 9df6dfe..7190e96 100644 --- a/sqs/queue_test.go +++ b/sqs/queue_test.go @@ -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)