--- tags: AAT disqus: hackmd --- # Message Queue ## Application Intergration - File Based Intergration - source application 根據要處理的任務,產生檔案到特定的路徑,其中任務成功或失敗可以存放到不同 folder 中。而其他接收訊息的 application(或稱 process application) 則是不停監控該路徑有沒有新檔案產生,有則取出檔案進行處理。 - Shared Database Intergration - 基本上方法和 file based 差不多: - source application 收到新任務時,將資料寫入 db 中 - process application 監聽的對象從路徑中的檔案換成 database,若有新資料則進行 處理 - process application 處理後將狀態寫回 db 中 - Direct Connection Intergration - source application 直接傳訊息給 process application - 可能透過 TCP/IP 或是 named pipe connection 的方式傳遞資料 - 傳遞資訊的資料格式並沒有限制,由連線兩端的 application 自訂,可以是純文字、XML 或 JSON。 - Asynchronous Message Broker  - 不限傳遞資料格式 - 需要額外 message queue middleware 協助,也會被稱作 message broker 或 message bus - message broker 收到來自 source application 的訊息後,會轉發給 process application,而在這個方式中,source application 與 process application 通常又各自被稱為 producer 與 **consumer。 ## RabbitMQ  ### Producer: 負責丟訊息到 Queue 中,若有定義 Exchange,則丟給 Exchange 決定要給誰。 ### Consumer: 負責接收來自 Queue 的訊息。 ### Queue: 負責存放所需要的資料,跟資料結構的 Queue 一樣,有先進先出 (FIFO) 特性,每個 Queue 都會有他的名字當 id。 ### Exchange: 用來決定 Producer 給的資料要丟給哪一個Queue,主要有這四種方式: - Direct: 直接丟給指定的 Queue。 - Topic: 類似 regular expression,設定 binding 規則,丟給符合的 Queue。 - Headers: 透過傳送資料的 header 來特別指定所要的 Queue。 - Fanout: 一次丟給全部負責的 Queue。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up