aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/sms/SnsSmsClient.java
diff options
context:
space:
mode:
authorSubodh Ranadive <subodh.ranadive@ekzero.com>2021-03-24 15:29:17 +0530
committerSubodh Ranadive <subodh.ranadive@ekzero.com>2021-03-24 15:30:32 +0530
commit6b6fde98cec480405010eae7a9b07db7ccd4ae82 (patch)
treeb03efdec2431763e8f3d7b9eb73c5d44ab991dce /src/main/java/org/traccar/sms/SnsSmsClient.java
parent6209400006ef3500adf64096dac84aa18dbf84e1 (diff)
downloadtrackermap-server-6b6fde98cec480405010eae7a9b07db7ccd4ae82.tar.gz
trackermap-server-6b6fde98cec480405010eae7a9b07db7ccd4ae82.tar.bz2
trackermap-server-6b6fde98cec480405010eae7a9b07db7ccd4ae82.zip
Async Exception handling
Diffstat (limited to 'src/main/java/org/traccar/sms/SnsSmsClient.java')
-rw-r--r--src/main/java/org/traccar/sms/SnsSmsClient.java22
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