Skip to content

Correct way to Get the Failed BatchRequestEntry when call SendMessageBatch #960

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

Closed
Tanych opened this issue Sep 12, 2018 · 4 comments
Closed
Labels
guidance Question that needs advice or information. wontfix We have determined that we will not resolve the issue.

Comments

@Tanych
Copy link

Tanych commented Sep 12, 2018

What platform/OS are you using?

Ubuntu
Linux b589473f479b 4.9.49-moby #1 SMP Wed Sep 27 00:36:29 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

What compiler are you using? what version?

g++ (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

What's your CMake arguments?

cmake -DBUILD_ONLY="s3;sqs;monitoring"

Can you provide a TRACE level log? (sanitize any sensitive information)

Questions

Currently, I am trying to get the failed batchrequestentry

bool SendMessageBatch(const std::string & sqs_url, const std::vector<std::string> &msgs)
{
	bool res=true;
	for (size_t i=0;i<msgs.size();i+=10)
	{
		auto send_request = Aws::SQS::Model::SendMessageBatchRequest().WithQueueUrl(sqs_url.c_str());
		size_t j=i;
		for(; j<std::min(i+10,msgs.size()); ++j){
			Aws::SQS::Model::SendMessageBatchRequestEntry entry;
			entry.SetId(std::to_string(j+1).c_str());
			entry.SetMessageBody(msgs[j].c_str());
			send_request.AddEntries(entry);
		}
		if (j > i){
			auto batch_outcome = m_sqs_client.SendMessageBatch(send_request);
			if (!batch_outcome.IsSuccess()){
				if (!batch_outcome.GetResult().GetFailed().empty()){
					for ( auto &fail_msg_entry : batch_outcome.GetResult().GetFailed()){
						auto msg_id_str = fail_msg_entry.GetId();
						auto it = std::find_if(send_request.GetEntries().begin(), send_request.GetEntries().end(),
								[&msg_id_str](const Aws::SQS::Model::SendMessageBatchRequestEntry& msg_entry) {return msg_entry.GetId() == msg_id_str;});
						// find and try again
						if(it!=send_request.GetEntries().end()) res &= SendMessage(sqs_url, it->GetMessageBody().c_str());
					}
				}
			}
		}
	}
	return res;
}

batch_outcome.GetResult().GetFailed() always be empty, even thogh the call is not successful, I definitely know there should be some failed messages.
What's the correct way to get the failed BatchRequestEntry ?

Thanks!

@Tanych Tanych changed the title Correct way to Get the Failed BatchRequestEntry when call SendMessageBatchRequest Correct way to Get the Failed BatchRequestEntry when call SendMessageBatch Sep 12, 2018
@singku
Copy link
Contributor

singku commented Sep 13, 2018

I think you misunderstood the meaning of IsSuccess(). It's about the status of the request in SDK level, not the high level status of service response. If IsSuccess() == false you should only call GetError() to investigate. If you want to call outcome.GetResult().GetFailed(), IsSuccess() must return true, means service returned response correctly, then you can look up if there is FAILED sqs request in the response.

@singku singku added the wontfix label Sep 13, 2018
@Tanych
Copy link
Author

Tanych commented Sep 13, 2018

@singku Thanks for your help.
I saw the doc says:

Because the batch  request can result in a combination of successful and 
unsuccessful actions, you should check for batch errors even when the
call returns an HTTP status code of 200

it means IsSuccess() is the same level of http 200, right?

@singku
Copy link
Contributor

singku commented Sep 13, 2018

Mostly yes. In most scenario, IsSuccess() means http code is < 300.

In this case based on the doc, even you get http 200, you should check your outcome for failed request.

@Tanych
Copy link
Author

Tanych commented Sep 13, 2018

thanks!

@singku singku closed this as completed Sep 13, 2018
@justnance justnance added guidance Question that needs advice or information. wontfix We have determined that we will not resolve the issue. and removed wontfix labels Apr 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information. wontfix We have determined that we will not resolve the issue.
Projects
None yet
Development

No branches or pull requests

3 participants