Reputation: 117
This is the code i found on SNS's official site to publish to a topic
String msg = "My text published to SNS topic with email endpoint";
PublishRequest publishRequest = new PublishRequest(topicArn, msg);
PublishResult publishResult = snsClient.publish(publishRequest);
System.out.println("MessageId - " + publishResult.getMessageId());
I am developing a chat app on for android using sns(it will also push notifications to the existing ios counterpart of the app)
if i want to publish to a single device directly can i give device's "ApplicationEndPointArn" instead of topicArn
Upvotes: 0
Views: 1308
Reputation: 3037
SNS is intended to decouple notification service from application layer.
We could create a topic and add mobile endpoints as subscribers.
When a message is published to the topic all subscribers will get notified.
Apart from this if you would really need single endpoint messaging you could try,
PublishRequest publishRequest = new PublishRequest();
publishRequest.setTargetArn(endpointArn);
publishRequest.setMessage("SOME MESSAGE");
snsClient.publish(publishRequest)
where endpointArn is a device endpoint.
But make sure that you persist this device endpoint when device is registered in SNS and use the same returned EndpointArn for further communication.
Upvotes: 0