javascript 是否可以在 JS 脚本上接收 Amazon SNS 消息?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9624619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:14:44  来源:igfitidea点击:

Is it possible to receive an Amazon SNS message on a JS script?

javascriptamazon-web-servicespublish-subscribeamazon-sns

提问by tvdias

I know some options using ruby on rails and/or node.js and PubNuB, a service that has many APIs so you can send/receive notifications between (almost) any platform.

我知道一些使用 ruby​​ on rails 和/或 node.js 和 PubNuB 的选项,该服务具有许多 API,因此您可以在(几乎)任何平台之间发送/接收通知。

I now how to send messages from PHP and how to receive them there using Amazon SNS, but how can I receive a push notification (a SNS message) on a JS/jQuery script?

我现在如何从 PHP 发送消息以及如何使用 Amazon SNS 在那里接收它们,但是如何在 JS/jQuery 脚本上接收推送通知(SNS 消息)?

Thanks.

谢谢。

采纳答案by Steve Campbell

Yes, but not directly and you'll have to poll for messages on a timer...

是的,但不是直接的,你必须在计时器上轮询消息......

In the Product Details pageunder the heading "Flexible", you'll see that none of the currently supported formats/transports can be hosted in the browser.

在“灵活”标题下的“产品详细信息”页面中,您将看到当前支持的格式/传输均无法在浏览器中托管。

However... Amazon SQSis one of the supported transports, and it in turn can be accessed from JavaScript - see an example app here: http://aws.amazon.com/code/Amazon-SQS/1254. (The example shows JavaScript accessing SQS).

但是…… Amazon SQS是受支持的传输方式之一,反过来可以从 JavaScript 访问它 - 请在此处查看示例应用程序:http: //aws.amazon.com/code/Amazon-SQS/1254。(该示例显示了 JavaScript 访问 SQS)。

You'd have to manually poll though, as there is no "push" to the browser with SQS.

不过,您必须手动轮询,因为使用 SQS 没有“推送”到浏览器。

(Alternatively, you could do it all server-side, and then you could use potentially use websockets to push the messages to the browser.)

(或者,您可以在服务器端完成所有操作,然后您可以使用潜在的 websockets 将消息推送到浏览器。)

回答by The Virtual Machinist

Use a service worker in your project and set up a Push Notification handler... I created a GCM project and made a little node.js server and it seems to receive messages from SNS... No polling required.

在您的项目中使用 Service Worker 并设置推送通知处理程序...我创建了一个 GCM 项目并制作了一个小 node.js 服务器,它似乎从 SNS 接收消息...不需要轮询。