差異處
這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
methodology:arch:changedevent [2016/09/28 22:33] tony |
methodology:arch:changedevent [2016/09/29 23:36] tony [WebHook - Pub/Sub] |
||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== 如何讓Client得知你系統的事件? (工作中) ====== | + | {{tag>webook PubSubHubBub pub/sub}} |
+ | ====== 如何讓Client得知你系統的事件? ====== | ||
===== Introduction ===== | ===== Introduction ===== | ||
不管是任何系統都會有自己特有事件,而使用者會對某些事件有興趣。對於不同的案例,會有不同的解法。這裡主要收集Study的結果。 | 不管是任何系統都會有自己特有事件,而使用者會對某些事件有興趣。對於不同的案例,會有不同的解法。這裡主要收集Study的結果。 | ||
===== Categories ===== | ===== Categories ===== | ||
==== WebHook - Pub/Sub ==== | ==== WebHook - Pub/Sub ==== | ||
- | 在這種方法中,Client扮演著subscriber;Server則為publisher。Client會透過Server提供的介面去註冊某個有興趣的訊息,而Server當發生了事件後,會把訊息送給對應的subscriber。\\ | + | 在這種方法中,Client扮演著subscriber;Server則為publisher。Client會透過Server提供的介面去註冊某個有興趣的訊息,而Server當發生了事件後,會把訊息送給對應的subscriber。參考Jenkins Notification Plugin的UI設計: (圖片來自: [[https://wiki.jenkins-ci.org/display/JENKINS/Notification+Plugin|link]])\\ |
+ | {{:methodology:arch:jenkins_plugin_notification.png|}}\\ | ||
+ | 以Jenkins的Plugin來說,User可以透過它的UI設定你的Client所接受的Format、Protocol(http、https、udp、tcp),有興趣的Event,還有要callback的URL。如果你的Server提供的介面是RestAPI,可以參考Google Drive的做法。最重要的就在於User願意接受你所提出的格式。\\ | ||
\\ | \\ | ||
使用這方法的應用有: [[https://developers.google.com/drive/v3/web/push|Google Drive]]、[[https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-triggers/|AZure]]、[[https://wiki.jenkins-ci.org/display/JENKINS/Notification+Plugin|Jenkins Plugin]]。 | 使用這方法的應用有: [[https://developers.google.com/drive/v3/web/push|Google Drive]]、[[https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-triggers/|AZure]]、[[https://wiki.jenkins-ci.org/display/JENKINS/Notification+Plugin|Jenkins Plugin]]。 | ||
==== WebHook – PubSubHubBub ==== | ==== WebHook – PubSubHubBub ==== | ||
+ | PubSubHubBub是一個Publish/Subscribe的開放標準,詳細介紹看[[https://zh.wikipedia.org/wiki/PubSubHubbub|這裡]]。我們直接說說操作過程(圖片來自[[http://ivanzuzak.info/2010/01/11/real-time-feed-processing-and-filtering.html|link]]):\\ | ||
+ | {{:methodology:arch:pshbarch.png|}}\\ | ||
+ | - Discovery: subscriber會先從publisher的topic_url取得hub_url,publisher回應格式是基於RSS或ATOM XML。 | ||
+ | - Subscribe: subscriber會到hub_url註冊有興趣的topic_url與要收通知的callback_url,callback_url通常被稱為webhook。 | ||
+ | - Publish: 當Publisher有事件發生會通知Hub,而Hub會去取得最新的事件。 | ||
+ | - Notify: Hub通知所有subscriber新增與改變的事件。 | ||
+ | 與一般的Pub/Sub最大差別,我想: | ||
+ | - PubSubHubBub通常會是一個外部服務,不太容易適用於內部網路;Pub/Sub比較容易用於內部網路。 | ||
+ | - 由於publisher只要通知Hub,即使有多個subscriber,也不會有巨大流量產生在publisher上;Pub/Sub是由publisher自己通知所有的subscriber。 | ||
+ | 因為我的需求是內部網路,之後有時間再深入試玩看看。 | ||
+ | \\ | ||
使用這方法的應用有: [[https://wordpress.org/plugins/pubsubhubbub/|WordPress Plugin]]、[[https://developers.google.com/youtube/v3/guides/push_notifications|YouTube]]、[[https://developer.github.com/v3/repos/hooks/|GitHub]]、[[https://www.instagram.com/developer/subscriptions/|Instagram]] | 使用這方法的應用有: [[https://wordpress.org/plugins/pubsubhubbub/|WordPress Plugin]]、[[https://developers.google.com/youtube/v3/guides/push_notifications|YouTube]]、[[https://developer.github.com/v3/repos/hooks/|GitHub]]、[[https://www.instagram.com/developer/subscriptions/|Instagram]] | ||
==== Poll ==== | ==== Poll ==== | ||
行 14: | 行 28: | ||
使用這方法的應用有: [[https://www.dropbox.com/developers-v1/core/docs|Dropbox]]、[[https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-triggers/|AZure]]。 | 使用這方法的應用有: [[https://www.dropbox.com/developers-v1/core/docs|Dropbox]]、[[https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-triggers/|AZure]]。 | ||
==== Longpoll ==== | ==== Longpoll ==== | ||
- | 使用這方法的應用有: [[https://www.dropbox.com/developers-v1/core/docs|Dropbox]]。 | + | Longpoll就是client會先連線至server。在一段時間內,如果server有任何改變就通知client;這段時間如果沒改變,也通知client沒改變。如果一段時間內,有頻繁的通知,client與server就要經歷多次的建立連線、通知、中斷連線循環。因此後來有websocket去解決這樣問題;網路上也有RestAPI+Websocket做法的討論,以後有用到再看看。更多可參考[[https://blog.gtwang.org/web-development/websocket-protocol/|此篇]]\\ |
+ | \\ | ||
+ | 使用這方法的應用有: [[https://www.dropbox.com/developers-v1/core/docs|Dropbox]],。 | ||
==== Hook Scripts ==== | ==== Hook Scripts ==== | ||
+ | 我最早使用Hook Scripts是在SVN時期,它可以針對不同事件發生時,執行你所提供的腳本。例如commit code後,觸發持續整合系統的建置;在commit之前,必須先做某些事情才允許commit等。(圖片來自: [[https://fr.atlassian.com/git/tutorials/git-hooks/conceptual-overview|link]])\\ | ||
+ | {{:methodology:arch:git_hook.png?700|}}\\ | ||
+ | 以Git Hook範例來說,在第二步驟執行後,會觸發Pre-Commit Notification;在Pre-Commit Notification成功後,接著執行第三步驟後,會觸發Post-Commit Notification。\\ | ||
+ | \\ | ||
+ | 如果提供Hook Scripts的方式,你可以不需要管Client長什麼樣,因為User可以根據它的需求去做對應的Script出來。(如果他提供無法跑的Script,那就是來亂的無誤)\\ | ||
+ | \\ | ||
使用這方法的應用有: [[https://git-scm.com/book/zh-tw/v1/Git-%E5%AE%A2%E8%A3%BD%E5%8C%96-Git-Hooks|Git]]、[[http://jdev.tw/blog/340/subversion-hook-scripts|Subversion]]。 | 使用這方法的應用有: [[https://git-scm.com/book/zh-tw/v1/Git-%E5%AE%A2%E8%A3%BD%E5%8C%96-Git-Hooks|Git]]、[[http://jdev.tw/blog/340/subversion-hook-scripts|Subversion]]。 | ||
行 21: | 行 43: | ||
* [[http://ivanzuzak.info/2010/01/11/real-time-feed-processing-and-filtering.html|Real-time feed processing and filtering]] | * [[http://ivanzuzak.info/2010/01/11/real-time-feed-processing-and-filtering.html|Real-time feed processing and filtering]] | ||
* [[https://zh.wikipedia.org/wiki/PubSubHubbub|Wiki - PubSubHubbub]] | * [[https://zh.wikipedia.org/wiki/PubSubHubbub|Wiki - PubSubHubbub]] | ||
+ | * [[https://blog.superfeedr.com/howto-pubsubhubbub/|How to implement PubSubHubbub?]] | ||
* [[http://stackoverflow.com/questions/15594905/difference-between-observer-pub-sub-and-data-binding|Difference between Observer, Pub/Sub, and Data Binding]] | * [[http://stackoverflow.com/questions/15594905/difference-between-observer-pub-sub-and-data-binding|Difference between Observer, Pub/Sub, and Data Binding]] | ||
* [[https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern|Publish–subscribe pattern]] | * [[https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern|Publish–subscribe pattern]] | ||
+ | * [[https://blog.gtwang.org/web-development/websocket-protocol/|WebSocket 通訊協定簡介:比較 Polling、Long-Polling 與 Streaming 的運作原理]] | ||
+ | * [[https://fr.atlassian.com/git/tutorials/git-hooks/conceptual-overview|git-hooks]] | ||
====== ====== | ====== ====== |