Reputation: 463
I'm trying to implement push notifications on my Java-based website(Using Struts 1.x). The goal is to make something similiar to what Stackoverflow and other sites have which notify a user in real-time when they get messages.
I'm using mysql as my database, Apache as my server, and am considering using Amazon-SNS as the framework for these notifications since that is what that service seems to be intended for.
Upvotes: 2
Views: 974
Reputation: 178956
On a "web site," no, that isn't what SNS really does.
SNS has two different modes of operation:
For real-time notifications to browsers, take a look at the source of the page you're looking at right now for a hint of how it's done:
<script type="text/javascript">
StackExchange.ready(function () {
StackExchange.realtime.init('wss://qa.sockets.stackexchange.com,ws://qa.sockets.stackexchange.com');
StackExchange.realtime.subscribeToInboxNotifications();
StackExchange.realtime.subscribeToReputationNotifications('1');
StackExchange.realtime.subscribeToTopBarNotifications('1');
});
</script>
That looks like a websocket connection, identified by wss://
(contrast with https://
). There are a variety of implementations of websockets, in various languages, that allow a component on your side to interact with the javascript running on the browser, and I would suggest that this is the closest thing to a standard mechanism for push notifications to modern web browsers.
SNS does not have a feature-set that offers this kind of integration to the browser, though it might be something you could use internally to relay messages from your application server to your websocket gateway(s), since SNS could provide a short-term buffer between the app server and the gateway, or the ability to broadcast a message to multiple gateways, if that's how you implemented it... the advantage of something like this would be that it would prevent the app server from being adversely impacted if the gateway were overloaded or offline. Theoretically websockets can be terminated by the application server itself, since they begin their connection over HTTP, but the longer life of a typical websocket connection compared to an http request can make this a bad combination.
Upvotes: 2