* (star) can substitute for exactly one word. # (hash) can substitute for zero or more words.
上面這個說法還是容易讓人誤解的,我嘗試解釋一下:
. 用來将routing key 分割成若幹部分(Part) * 比對一個完整的Part # 比對一個或者多個Part
驗證上面的結論很簡單,我們可以使用Client建立不同Exchange來驗證這一點;還有一個更為簡單的方法就是找到RabbitMQ這部分實作邏輯,顧名思義很容易找到..\rabbitmq-server-2.8.7\src\rabbit_exchange_type_topic.erl檔案,最新版本的代碼這部分邏輯已經寫得比較複雜,回溯到更早的版本rabbitmq-server-2.2.0\src\rabbit_exchange_type_topic.erl,這個就清晰多了,看它的代碼:


看代碼,一切都明了了,看下面的測試代碼:
rabbit_exchange_type_topic:topic_matches
檢驗一下是否真的了解了,嘗試回答一下Tutorials文檔最後的幾個變态問題:
Will "*" binding catch a message sent with an empty routing key?
Will "#.*" catch a message with a string ".." as a key? Will it catch a message with a single word key?
How different is "a.*.#" from "a.#"?
最後,小圖一張,晚安!