DukeHuangWp
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `Plus` `RabbitMQ` # RabbitMQ 學習筆記: ## MQTT與HTTP定位: > > MQTT和HTTP的底層都是TCP/IP,也就是物聯網裝置可以沿用既有的網路架構和設備,只是在網路上流通的「訊息格式」以及應用程式的處理機制不同。 > > ![mqtt_tcp_ip](https://github.com/DukeHuangWP/HackMD/blob/2021-01-01/RabbitMQ%20%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98/mqtt_tcp_ip.png?raw=true) > > ![mqtt_messge](https://github.com/DukeHuangWP/HackMD/blob/2021-01-01/RabbitMQ%20%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98/mqtt_messge.png?raw=true) > > > ![mqtt_message_format](https://github.com/DukeHuangWP/HackMD/blob/2021-01-01/RabbitMQ%20%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98/mqtt_message_format.png?raw=true) > > 使用發佈(Publish) / 訂閱(Subscribe)的機制傳訊,4個主要的元素: > > |QoS類型| > |-| > |發佈者 (Publisher)| > |訂閱者 (Subscriber)| > |主題 (Topic)| > |轉訊站 (Broker)| > > |QoS類型|特性|注意點| > |-|-|-| > |QoS 0| 最多傳送一次(at most once),Broker不會回傳確認封包給Publisher|不保證訊息會送達| > |QoS 1| 至少傳送一次(at least once),Publisher未收到Broker回傳封包時會再度發送| 可能會接收到重複訊息 | > |QoS 2| 確實傳送一次(exactly once),Publisher先與Broker確認連線後, Broker才會發送訊息到Subscriber,並再度與回傳確認封包給Publisher| 最安全可靠,佔用頻寬與傳送時間較多 | > > > ![publisher_broker_subscriber](https://github.com/DukeHuangWP/HackMD/blob/2021-01-01/RabbitMQ%20%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98/publisher_broker_subscriber.png?raw=true) ## Queue隊列處理效果分析: > ##### 異步處理vs同步處理: > <iframe > style="frameborder:0;border:0;scrolling:no;background-color:#4e4e4e;width:100%;height:150px" > src="http://www.plantuml.com/plantuml/svg/SoWkIImgAStDuSf9JIjHACbNACfCpoXHICaiIaqkoSpFuohEpimhI2nAp5KeI4pEJanF3Iwfp4bL04advgNdf79nSS7P2aydz3nRk_J5pAdF9xIztzFnSiRkfmldlT_JgPnUb5XPpPMON99Vf11Qd5ga01RXKe1mT7Nj59GC3NABbHGqddRsFktVyAnlwRCfspHX2cngzFHmg00gGHP0CGlYa1UhkvzjRD94KmWn4uTIe5fa0HH3dqtTyMpohAUxLZ_Vql2ofqKJJItSN5FigckvkFpoIr8LmE6TdwQW0VAWffN2iuw9ptViVTgwyVdQpYUxsio0shaSKlDIW7430000"> > </iframe> > > <iframe > style="frameborder:0;border:0;scrolling:no;background-color:#4e4e4e;width:75%;height:150px" > src=" > http://www.plantuml.com/plantuml/svg/SoWkIImgAStDuSf9JIjHACbNACfCpoXHICaiIaqkoSpFuohEpimhI2nAp5KeI4pEJanF3Iwfp4bL04advgNdf7B1MGhFfsvujdRfYvbJdqzeKr1EBqgihEPIK4XCBialKWWjJYs2Y741nS0yNLqx1IL3WznY9GMDfvszJ_itFEjR-cpADasO0fiQFJqSAe1Aa0KGPiNa0TL2dF1YTVUpZKsQQ4eXfa8KeoabPEopgJkUJPxrTDVgvriQNlQqu3JPDBSOc-fQBh_yabG5S43dfobeWFoeQQNmh6FYynrxdxPkVBwsyyckDXEWRYw7rBmKOAG00000 > "> > </iframe> > > ##### 異步處理使用Queue隊列: > <iframe > style="frameborder:0;border:0;scrolling:no;background-color:#4e4e4e;width:100%;height:300px" > src=" > http://www.plantuml.com/plantuml/svg/SoWkIImgAStDuSf9JIjHACbNACfCpoXHICaiIaqkoSpFuohEpimhI2nAp5KeI4pEJanF3Iwfp4bL04advgNdf7B1MGhFfsvujdRfYvbJdqzeqtYwPDQJNRiq5PJJYn8hgxaK51AJI_AB54ABKuiC8O8eOaPmCOHvJpjxd_PlUDQtzDcKRIWI42jUhEv-jh49HUBPr1tF9izwkclryoqDBtjQk82I40jrTUqKb0mDSekL53IGZTM4gx2fqTF3eGIgneYWAKRuJK4JGJ4EsKkQc4fjWCPYLJjGvgA5D6wZJR4ffxdfjLn--IMf2k14dP-ce06EOqqhXMST4v_sht_HlFVvsiudkzfCWFgng3J2L6bk05Jfa9gN0imh0000 > "> > </iframe> > > <iframe > style="frameborder:0;border:0;scrolling:no;background-color:#4e4e4e;width:100%;height:300px" > src=" > http://www.plantuml.com/plantuml/svg/XT9DIm917CVn-xoAFzl5FIYvH44iuYi88hfr6NJS5dTsPMRs81L4b6ZFKH9vpfC82X6oqBjnPlLTPEwoRAbvMtxxvGCpJ94Bp8HF7UIGYW3X0REjOm5bcv6Ii3qNyQhjrZ3356guLCKMEH1rXy3FR-nQ3a795uJjWUft9s_jyB6HaU-TSH3i-yGdqywrRBxgi64nN3z10BWaF0Q7dB1yDFxQZ6Ihs3DLcnkHge5fojQTV1Ye-wvw-ImK07D8BmX136Up1T3ocvHha4aNUbAOfxdSYYHkZBMAiKP93p6Mf_p8dRNHaIQz6pMyqF-cvWoDseLokReTgwezKiyT6VJ2Z_FfxUN_y49yXlOyGM3-6BmAPEONfU-2QZw5eozvDGpxhN7GsDgXV4bfh2YBn2txrFa6 > "> > </iframe> ## RabbitMQ架構簡介: > > **RabbitMQ三大主體架構:** > * ==Publisher(生產者)== : 即寄信人,負責發送訊息(Message). > * ==Broker(代理人)== : 負責處理訊息傳遞,為RabbitMQ的服務主體:由多個==Virtual Host==組成. > * ==Consumer(消費者)== : 即收件人,接收訊息者. > > **RabbitMQ服務主體Broker(代理人):** > > * ==Broker==為RabbitMQ的服務主體,負責訊息傳遞策略,由多個 ==Virtual Host(虛擬器)== 組成. > * 每個==Virtual Host(虛擬器)== : 由一個==Exchange(交換器)== 與多個==Queue(隊列)== 所組成. > * ==Exchange== 和多個 ==Queue== 之間稱為==Binding(關聯)== (詳細內容請看之後工作模式設置). > * ==Queue== 和多個 ==Consumer(消費者)== 相互==Connecction(連線)== ,透過多個==Channel== 所組成. > > ![publisher_broker_subscriber]( >https://raw.githubusercontent.com/DukeHuangWP/HackMD/2021-01-01/RabbitMQ%20%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98/RabbitMQ_Flow_Diagram.svg > ) > ## RabbitMQ - 安裝: > > 參考: https://www.rabbitmq.com/download.html > https://andyyou.github.io/2017/06/08/rabbitmq-notes/ > #### MacOS - Homebrew 設定 > ==/usr/local/etc/rabbitmq/rabbitmq-env.conf== > ```bash > CONFIG_FILE=/usr/local/etc/rabbitmq/rabbitmq > # NODE_IP_ADDRESS=127.0.0.1 #屏蔽後才能給外網使用amqp > NODENAME=rabbit@localhost > RABBITMQ_LOG_BASE=/usr/local/var/log/rabbitmq > ``` > #### MacOS - Homebrew 設定 > ```bash > #直接启动 > rabbitmq-server > > #后台启动 > rabbitmq-server -detached > > #查询进程 > ps -ef|grep rabbitmq > > #关闭 > rabbitmqctl stop > > #检查状态 > rabbitmqctl status > > rabbitmqctl help > > #add_user username password > rabbitmqctl add_user tonyg changeit > #delete_user username > rabbitmqctl delete_user tonyg > #change_password username newpassword > rabbitmqctl delete_user tonyg > #clear_password username > rabbitmqctl clear_password tonyg > ``` > > #### RabbitMQ Web管理介面 > 官方預設:http://localhost:15672/ > 預設帳號:`guest` > 預設密碼:`guest` > > ![](https://i.imgur.com/WXNb6pz.png) ## RabbitMQ - Exchange Model工作模式: > > ![exchanges]( > https://tedmax100.github.io/images/MQ/exchanges-topic-fanout-direct.png > ) > > ![](https://github.com/DukeHuangWP/HackMD/blob/2021-01-01/RabbitMQ%20%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98/RabbitMQ_WebGUI_Exchanges.png?raw=true) --- > #### Exchange 設置 > |Exchange Type|敘述|Queue RoutingKey|敘述| > |-|-|-|-| > |Fanout|廣播|選用設定| > |Direct|指定|必須設定|RoutingKey必須符合才能消費| > |Topic|規格|選用設定|RoutingKey:`.#` `.*` ` `| > * Topic RoutingKey > > > ` `:只有RoutingKey為空者符合 > > `.#` : ==.!@==、==.99== 不限字數皆符合 > > `.*`: ==.!==、==.99== 字數一位皆符合 > > > |Exchange 參數| 說明 | > |-|-| > |Name| 交換機名稱,消費者與生產者皆需要設定,否則Broker將以預設作代替| > |Type| 交換機工作模式: `Fanout` `Direct` `Topic` `Headers`| > |durable| 交換機名稱,消費者與生產者皆需要設定,否則Broker將以預設作代替| > |autoDelete| 當最後消費完成後自我刪除Queue| > |exclusive| 交換機是否遭單Queue獨佔(僅一個連線能使用其他人使用則回報RESOURCE_LOCKED錯誤)| > |no-wait| | > * ==Exchange 參數不論消費者或生產者設定必須一致避免無法預期的問題== > > > --- > #### Queue 設置 > |Queue 參數| 說明 | > |-|-| > |Name| Queue名稱,消費者需要設定(僅創建時需要設定)| > |durable| Broker關機是否保存Queue| > |autoDelete| 當最後消費完成後自我刪除Queue| > |exclusive| 交換機是否遭消費者獨佔(僅一個連線能使用其他人使用則回報RESOURCE_LOCKED錯誤)| > |no-wait| | > > |Queue Bind 參數| 說明 | > |-|-| > |Exchange Name| 交換機名稱,消費者需要設定(需要在交換機後設定Bind)| > |Queue Name| Queue名稱,消費者需要設定(需要在Queue後設定Bind)| > |durable| Routing Key| > |no-wait| | ## RabbitMQ外網設置 ==/usr/local/etc/rabbitmq== ```bash= CONFIG_FILE=/usr/local/etc/rabbitmq/rabbitmq #NODE_IP_ADDRESS=127.0.0.1 NODENAME=rabbit@localhost RABBITMQ_LOG_BASE=/usr/local/var/log/rabbitmq ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    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

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully