Skip to content

Commit

Permalink
Updated SQS hello-world example (#512)
Browse files Browse the repository at this point in the history
* SQS hello-world example was missing required message_group_id parameter for send_message call

* Updated SQS hello world example based on feedback

Co-authored-by: Russell Cohen <rcoh@amazon.com>
  • Loading branch information
Doug-AWS and rcoh authored Jun 21, 2021
1 parent c4ee9f0 commit 0f534f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
9 changes: 3 additions & 6 deletions aws/sdk/examples/sqs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
[package]
name = "sqs"
name = "sqs-code-examples"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>"]
authors = ["Russell Cohen <rcoh@amazon.com>", "Doug Schwartz <dougsch@amazon.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sqs = { package = "aws-sdk-sqs", path = "../../build/aws-sdk/sqs" }
tokio = { version = "1", features = ["full"] }
tracing-subscriber = "0.2.18"

[[bin]]
name = "sqs-hello-world"
tracing-subscriber = "0.2.18"
17 changes: 12 additions & 5 deletions aws/sdk/examples/sqs/src/bin/sqs-hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use std::process::exit;

/// Sends a message to and receives the message from a queue.
#[tokio::main]
async fn main() -> Result<(), sqs::Error> {
tracing_subscriber::fmt::init();
Expand All @@ -18,25 +19,31 @@ async fn main() -> Result<(), sqs::Error> {
exit(1);
}
};
println!("sending a receiving on `{}`", queue_url);

println!(
"Sending and receiving messages on with URL: `{}`",
queue_url
);

let rsp = client
.send_message()
.queue_url(&queue_url)
.message_body("hello from my queue")
.message_group_id("MyGroup")
.send()
.await?;
println!("sent a message: {:#?}", rsp);

println!("Response from sending a message: {:#?}", rsp);

let rcv_message_output = client
.receive_message()
// TODO: this should not be required, https://github.com/awslabs/smithy-rs/issues/439
.max_number_of_messages(1)
.queue_url(&queue_url)
.send()
.await?;

for message in rcv_message_output.messages.unwrap_or_default() {
println!("got a message: {:#?}", message);
println!("Got the message: {:#?}", message);
}

Ok(())
}

0 comments on commit 0f534f0

Please sign in to comment.