Last active
October 15, 2021 13:40
-
-
Save Catherine-K-George/e579ae463fc41ca40ac314d187a71568 to your computer and use it in GitHub Desktop.
How to deliver single & batch messages to a specified Amazon SQS Queue in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AWSSQS | |
class SQS { | |
func send(_ model: Encodable, to queueURL: String) -> () { | |
guard let messageString = model.jsonString() else { return } | |
let sqs = AWSSQS.default() | |
let sendMsgRequest = AWSSQSSendMessageRequest() | |
sendMsgRequest?.queueUrl = queueURL | |
sendMsgRequest?.messageBody = messageString | |
sqs.sendMessage(sendMsgRequest!) { (result, err) in | |
if let result = result { | |
print("Successfully sent (1) message. SQS messageId: \(String(describing: result.messageId)) , \(String(describing: model.jsonString()))") | |
} | |
if let err = err { | |
print("SQS sendMessage error: \(err)") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment