2015-06-02 108 views
1

我正在使用AWS SNS服務將警報消息發送給用戶phone.However用戶取消訂閱該主題仍然他從該主題獲取消息。停止獲取消息用戶發送消息STOP .Following用於創建和訂閱主題的代碼片段。AWS SNS服務SMS取消訂閱

CreateTopicRequest createTopicRequest = new CreateTopicRequest(topicName); 
CreateTopicResult createTopicResult = snsClient.createTopic(createTopicRequest); 

//Topic display name 
SetTopicAttributesRequest setTopicAttributesRequest = new SetTopicAttributesRequest(); 
setTopicAttributesRequest.withTopicArn(createTopicResult.getTopicArn()); 
setTopicAttributesRequest.setAttributeName(topicAttributeName); 
setTopicAttributesRequest.setAttributeValue(topicAttributeValue); 
snsClient.setTopicAttributes(setTopicAttributesRequest); 

SubscribeRequest subRequest = new SubscribeRequest(createTopicResult.getTopicArn(), "sms","12712438216"); 
snsClient.subscribe(subRequest); 
+0

添加完整的詳細信息和相關代碼.. –

+0

@SaketMittal添加的代碼片斷 – Niks

回答

0

這個怎麼樣?

  1. 列出了所有訂閱
  2. 循環,直到你找到端點( 「12712438216」),然後得到阿爾恩
  3. 執行退訂()函數。

    ListSubscriptionsResult listResult = snsClient.listSubscriptions(); 
    List<Subscription> subscriptions = listResult.getSubscriptions(); 
    String arn=""; 
    for (Subscription subs : subscriptions) { 
        if(subs.getProtocol().equals("sms") && subs.getEndpoint().equals("12712438216")) { 
         arn = subs.getTopicArn(); 
         break; 
        } 
    } 
    if(!arn.equals("")) { 
        snsClient.unsubscribe(arn); 
    } 
    
+0

,我可以用我的application..However做,如果用戶自己通過發送消息STOP至30304做退訂請求。我無法跟蹤它... – Niks

+0

是的,你無法跟蹤它。 – Rodel

+0

有什麼我失蹤? – Niks