differences between webhook and websocket

前端 未结 2 1847
耶瑟儿~
耶瑟儿~ 2021-01-29 18:22

I\'ve always wanted to do a real-time chat.

I\'ve done that years ago in PHP+Ajax+Mysql and broke my server. Then I tried with Flash+ a text file. I gave up and haven\'t

2条回答
  •  不思量自难忘°
    2021-01-29 19:06

    Here is some additional information for choosing between webhooks and websockets.

    Server-to-server communications over websockets has become popular with a new generation of chatbot apps. Now, many chatbots run over websockets with provide a primary advantage of not requiring a public facing URL for internal, private bots. In this environment the following are some guidelines on when to consider using webhooks vs. websockets.

    Websockets

    • If your app is a browser app, use websockets because your app cannot receive webhooks.
    • If your app is a server app receiving messages from a service over the Internet and you do not want to open your firewall, consider websockets. Some companies require information security review before opening such connections.

    Webhooks

    • If your server app app needs to make many subscriptions, either be prepared to handle the volume of open websocket connections to your sever (see this article for 1M websocket connections), or switch to webhooks. Some popular chatbots have moved from websockets to webhooks to improve scalability.
    • If your server app runs as a cloud function on (AWS Lambda, Google Cloud Functions, etc.), use webhooks because your app will not keep the websocket connection open.
    • If your server app is running on the Heroku free tier, use webhooks because your Dyno will go to sleep and must sleep for 6 hours per day, unless you manually instruct your server to sleep.

提交回复
热议问题