diff options
author | Subodh Ranadive <subodh.ranadive@ekzero.com> | 2021-03-24 15:29:17 +0530 |
---|---|---|
committer | Subodh Ranadive <subodh.ranadive@ekzero.com> | 2021-03-24 15:30:32 +0530 |
commit | 6b6fde98cec480405010eae7a9b07db7ccd4ae82 (patch) | |
tree | b03efdec2431763e8f3d7b9eb73c5d44ab991dce /src | |
parent | 6209400006ef3500adf64096dac84aa18dbf84e1 (diff) | |
download | trackermap-server-6b6fde98cec480405010eae7a9b07db7ccd4ae82.tar.gz trackermap-server-6b6fde98cec480405010eae7a9b07db7ccd4ae82.tar.bz2 trackermap-server-6b6fde98cec480405010eae7a9b07db7ccd4ae82.zip |
Async Exception handling
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/sms/SnsSmsClient.java | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/sms/SnsSmsClient.java b/src/main/java/org/traccar/sms/SnsSmsClient.java index 6089d4f38..1741b5559 100644 --- a/src/main/java/org/traccar/sms/SnsSmsClient.java +++ b/src/main/java/org/traccar/sms/SnsSmsClient.java @@ -18,11 +18,13 @@ package org.traccar.sms; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.handlers.AsyncHandler; import com.amazonaws.services.sns.AmazonSNSAsync; import com.amazonaws.services.sns.AmazonSNSAsyncClientBuilder; import com.amazonaws.services.sns.model.MessageAttributeValue; import com.amazonaws.services.sns.model.PublishRequest; +import com.amazonaws.services.sns.model.PublishResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.Context; @@ -58,12 +60,20 @@ public class SnsSmsClient implements SmsManager { new MessageAttributeValue().withStringValue("SNS").withDataType("String")); smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue().withStringValue("Transactional").withDataType("String")); - try { - snsClient.publishAsync(new PublishRequest().withMessage(message) - .withPhoneNumber(destAddress).withMessageAttributes(smsAttributes)); - } catch (RuntimeException exception) { - LOGGER.warn("SMS send failed", exception); - } + + PublishRequest pubReq = new PublishRequest().withMessage(message) + .withPhoneNumber(destAddress).withMessageAttributes(smsAttributes); + + snsClient.publishAsync( pubReq, new AsyncHandler<PublishRequest, PublishResult>() { + @Override + public void onError( Exception exception) { + LOGGER.error("SMS send failed", exception); + } + @Override + public void onSuccess( PublishRequest request, PublishResult result ) { + LOGGER.info("SMS sent successfully"); + } + }); } @Override |