【发布时间】:2015-05-18 22:35:55
【问题描述】:
根据documentation 所说,如果我达到最大发送速率,我会收到错误消息。我的最大发送速率是每秒 14 封电子邮件,我尝试同时发送 100 封邮件,所有邮件都到达了收件人。
所以我想知道为什么 Amazon SES 没有发送任何“信号”来抱怨我的过度或轻松,为什么 Amazon SES 在原本应该只发送 14 封的情况下却发送了所有这 100 封电子邮件。
这是我使用的代码:
List<String> destinations = new ArrayList<>(); //replace with your TO email addresses
for (int i = 0; i < 100; i++) {
destinations.add("Receiver address");
}
int i=0;
for (String destination : destinations) {
new Thread("" + i){
public void run(){
System.out.println("Thread: " + getName() + " running");
int maxRetries = 10;
while(maxRetries-->0) {
try {
// Create the subject and body of the message.
Content subject = new Content().withData("Asunto");
Content textBody = new Content().withData("cuerpo");
Body body = new Body().withText(textBody);
// Create a message with the specified subject and body.
Message message = new Message().withSubject(subject).withBody(body);
Destination destination2 = new Destination().withToAddresses(new String[]{destination});
// Assemble the email.
SendEmailRequest request = new SendEmailRequest().withSource("fromnaddres").withDestination(destination2).withMessage(message);
//wait for a permit to become available
//rateLimiter.acquire();
//call Amazon SES to send the message
SendEmailResult result = client.sendEmail(request);
System.out.println("sent "+result.getMessageId());
break;
} catch (AmazonServiceException e) {
//retries only throttling errors
System.out.println("hola");
if ("Throttling".equals(e.getErrorCode()) && "Maximum sending rate exceeded.".equals(e.getMessage())) {
System.out.println("Maximum send rate exceeded when sending email to "+destination+". "
+(maxRetries>1?"Will retry.":"Will not retry.") );
} else {
System.out.println("Unable to send email to: "+destination+". " +e.toString());
break;
}
} catch(Exception e) {
System.out.println("Unable to send email to: "+destination+". " +e.toString());
break;
}
}
}
}.start();
i++;
}
【问题讨论】:
-
那你有什么问题?
-
在您没有达到限制的任何时期之后,可能会有少量的突发允许。 [需要引用]
-
@alexandresaiz 问题是我无法测试最大发送速率情况下的行为
-
@Michael-sqlbot 这是
标签: java email amazon-ses