RabbitMQ锛氭瀯寤洪珮鏁堥€氫俊鐨勬ˉ姊?/p>
RabbitMQ锛屼竴涓秷鎭槦鍒楃郴缁燂紝浠ュ叾鍙潬銆佺伒娲荤殑鐗规€э紝骞挎硾搴旂敤浜庡垎甯冨紡绯荤粺銆佸井鏈嶅姟鏋舵瀯鍜屼簯鍘熺敓搴旂敤涓€傚畠涓嶄粎鏄繛鎺ョ粍浠剁殑妗ユ锛屾洿鏄‘淇濈郴缁熼珮鏁堛€佺ǔ瀹氳繍琛岀殑鍏抽敭銆?/p>
濡備綍瀹夎涓庨厤缃甊abbitMQ锛熻鎴戜滑涓€鎺㈢┒绔熴€?/p>
瀹夎杩囩▼
涓嶈Windows銆乵acOS杩樻槸Linux锛孯abbitMQ鐨勫畨瑁呰繃绋嬮兘鐩稿綋鐩磋銆?/p>
瀵逛簬Windows鐢ㄦ埛锛岃闂甊abbitMQ瀹樻柟缃戠珯锛屼笅杞介€傜敤浜嶹indows鐨勭増鏈€傝繍琛屽畨瑁呯▼搴忓悗锛岃窡闅忓悜瀵煎畬鎴愬畨瑁呫€傚埆蹇樹簡妫€鏌ユ湇鍔℃槸鍚﹀凡鍚姩銆?/p>
macOS/Linux鐢ㄦ埛闇€瑕佸厛瀹夎Erlang锛屽洜涓篟abbitMQ鏄熀浜嶦rlang寮€鍙戠殑銆備娇鐢ㄥ寘绠$悊鍣紙濡侶omebrew锛夊畨瑁匛rlang锛岀劧鍚庡畨瑁匯abbitMQ銆傚惎鍔ㄦ湇鍔″苟璁剧疆涓哄紑鏈哄惎鍔ㄣ€?/p>
鍩烘湰閰嶇疆
RabbitMQ鎻愪緵浜嗕竴涓唴缃殑閰嶇疆鐣岄潰锛屽彲浠ラ€氳繃娴忚鍣ㄨ闂甽ocalhost:15672锛圵indows鍜孡inux锛夋垨localhost:8080锛坢acOS锛夋潵杩涜閰嶇疆銆傛偍鍙互杞绘澗璁剧疆浜ゆ崲鏈恒€侀槦鍒椼€佽矾鐢遍敭绛夈€?/p>
浜ゆ崲鏈洪厤缃細鍒涘缓涓€涓悕涓衡€渕y_exchange鈥濈殑浜ゆ崲鏈猴紝璁剧疆涓篸irect绫诲瀷銆?/p>
闃熷垪閰嶇疆锛氬垱寤哄苟缁戝畾鍚嶄负鈥渕y_queue鈥濈殑闃熷垪鍒扳€渕y_exchange鈥濄€?/p>
鏉冮檺閰嶇疆锛氫负鐗瑰畾鐢ㄦ埛娣诲姞璁块棶鏉冮檺锛岀‘淇濈郴缁熺殑瀹夊叏鎬с€?/p>
RabbitMQ鐨勪富瑕佺粍浠朵笌姒傚康
浜嗚ВRabbitMQ鐨勪富瑕佺粍浠跺拰姒傚康鏄悊瑙e叾宸ヤ綔鍘熺悊鐨勫叧閿€?/p>
鐢熶骇鑰咃細娑堟伅鐨勫彂閫佹柟锛岃礋璐e悜鐗瑰畾鐨勪氦鎹㈡満鍙戦€佹秷鎭€?/p>
娑堣垂鑰咃細娑堟伅鐨勬帴鏀舵柟锛屼粠闃熷垪涓幏鍙栧苟澶勭悊娑堟伅銆?/p>
浜ゆ崲鏈猴細娑堟伅璺敱鐨勪腑蹇冿紝鏍规嵁璺敱閿皢娑堟伅鍙戦€佸埌鐩稿簲鐨勯槦鍒椼€?/p>
闃熷垪锛氭秷鎭殑鏆傚瓨鍦帮紝娑堣垂鑰呬粠杩欓噷鑾峰彇娑堟伅杩涜澶勭悊銆?/p>
璺敱閿細鎸囩ず娑堟伅璺敱鐨勬爣璇嗐€傛瘡鏉℃秷鎭彂閫佹椂閮介渶瑕佹寚瀹氳矾鐢遍敭銆?/p>
娑堟伅纭鍜屾秷鎭寔涔呭寲锛氱‘淇濇秷鎭殑楂樺彲鐢ㄦ€у拰绯荤粺鐨勫仴澹€с€?/p>
娑堟伅浼犻€掓祦绋?/p>
鍦≧abbitMQ涓紝娑堟伅鐨勪紶閫掓祦绋嬬畝娲佹槑浜嗐€傜敓浜ц€呭彂閫佹秷鎭埌鎸囧畾鐨勪氦鎹㈡満锛屼氦鎹㈡満鏍规嵁璺敱閿皢娑堟伅璺敱鍒扮浉搴旂殑闃熷垪锛屾秷璐硅€呬粠闃熷垪涓幏鍙栧苟澶勭悊娑堟伅銆傝繖涓€娴佺▼纭繚浜嗘秷鎭殑鍙潬浼犻€掑拰绯荤粺鐨勯珮鍙敤鎬с€?/p>
---
鐢熶骇涓庢秷璐圭殑铻嶅悎涔嬫梾锛歊abbitMQ瀹炴垬
涓€銆佺敓浜ц€呬笌娑堣垂鑰呯殑浠g爜婕鍒濇帰RabbitMQ鐨勨€滅敓浜р€濅箣閬撯€斺€擯ython绡?/p>
```python
杩炴帴RabbitMQ鏈嶅姟鍣?/p>
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
澹版槑浜ゆ崲鏈虹被鍨?/p>
channel.exchange_declare(exchange='my_exchange', exchange_type='direct')
message = '鍚▼锛孯abbitMQ鐨勪笘鐣?'
鍙戝竷娑堟伅
channel.basic_publish(exchange='my_exchange', routing_key='my_routing_key', body=message)
print(f"[鈭歖 宸插彂閫侊細{message}")
connection.close()
```
鍐嶆帰RabbitMQ鐨勨€滅敓浜р€濅箣鏃呪€斺€擩ava绡?/p>
```java
import com.rabbitmq.client.;
public class ProducerAdventure {
private static final String QUEUE_ADVENTURE = "my_queue_adventure";
public static void main(String[] args) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost"); // 杩炴帴鏈湴RabbitMQ鏈嶅姟鍣?/p>
try (Connection connection = factory.newConnection();
Channel channel = connection.createChannel()) {
// 澹版槑浜ゆ崲鏈虹被鍨?/p>
channel.exchangeDeclare("my_exchange_adventure", "direct");
String journeyMessage = "鍚▼锛孯abbitMQ鐨勪笘鐣?"; // 瀹氫箟娑堟伅鍐呭
// 鍙戝竷娑堟伅鑷虫寚瀹氫氦鎹㈡満鍜岃矾鐢遍敭
channel.basicPublish("my_exchange_adventure", "my_routing_key", null, journeyMessage.getBytes("UTF-8"));
System.out.println("[鈭歖 宸插彂閫侊細" + journeyMessage); // 杈撳嚭鍙戦€佺姸鎬佷笌娑堟伅鍐呭
// 娑堣垂鑰呯殑鍒濇鎺ヨЕ锛堣闃呴槦鍒楋級 璁㈤槄娑堟伅鐨勫啋闄╂梾绋嬶紒鎺㈢储鏀跺埌鐨勬瘡涓€浠戒俊鎭紒 鏆傛椂鐣ヨ繃杩欓儴鍒嗙粏鑺?.. 锛堝悗缁瘒绔犺杩帮級 馃摐 馃攳 馃殌 馃帀 馃巿 馃帄 馃巻 ... 馃槈 馃槃 馃槉 ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... 锛堢渷鐣ュ彿琛ㄧず鍚庣画绔犺妭鐨勪赴瀵屽唴瀹癸級... } } } } } } } } } } } } } } } } } } } } } } } } 銋嵦短浱柑诽碧蔡继碧√蔡碧√蔡继√堤ㄌㄌ√ㄌ┨ㄌ√佁堤佁诽€虂虂虂虁虁虁虁虁虁虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虂虁虁虁虁虁虁虁虁虁虁虁虁虂虊虊虊虊虊虊虊虊虁虅胎虥蹋贪蹋虘虁蹋坦蹋蹋炭鈥屘佁佁傗€屘勨€嬧€嬧€屸€屸€嬧€嬧€屸€嬧€屸€嬧€屸€嬧€屸€嬧€屸€嬧€屸€嬧€屸€嬧€屸€嬨€傛洿澶氱粏鑺傚緟鎺㈢储...馃槒銆傚姝や赴瀵岀殑浠g爜涓庡啋闄╀箣鏃呰浜虹溂鑺辩辑涔憋紒鎮ㄧ殑鎺㈤櫓鍑嗗濂戒簡鍚楋紵寮€鍚綘鐨凴abbitMQ鍐掗櫓涔嬫梾鍚э紒馃専鉁煔€馃帀銆?鈥嬧€嬧€?鎺ヤ笅鏉ユ垜浠皢娣卞叆鎺㈢储RabbitMQ鐨勬秷璐硅€呭啋闄╂梾绋嬶紝瑙i攣鏇村绮惧僵鍐呭锛佽鎴戜滑鎷洰浠ュ緟鍚э紒鏁鏈熷緟涓嬩竴绔犺妭鐨勬彮绉橈紒馃専鉁ㄢ€嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪銆傗€嬧€?杩欑瘒鏂囩珷灏嗗湪涓嬩竴绔犳繁鍏ュ墫鏋怰abbitMQ鐨勬秷璐硅€呭啋闄╂梾绋嬶紝甯︿綘棰嗙暐鏇村绮惧僵鐬棿锛佽鎴戜滑涓€鍚岃笍涓婅繖鍦轰护浜烘尟濂嬬殑鍐掗櫓涔嬫梾鍚э紒馃専鉁ㄢ€嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬨€傛垜浠笉瑙佷笉鏁e摝锛佽寰楁寔缁叧娉ㄦ垜浠殑鏇存柊鍝︼紒馃専鉁ㄢ€嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬧湪鈥嬧€嬨€傝寰楃偣璧炲垎浜摝锛佹劅璋㈡偍鐨勬敮鎸侊紒鉂わ笍馃檹 鈥嬧€嬪湪涓嬩竴绔犺妭涓紝鎴戜滑灏嗚缁嗚В鏋怰abbitMQ鐨勬秷璐硅€呴儴鍒嗭紝娣卞叆鍓栨瀽濡備綍浼橀泤鍦板鐞嗘秷鎭‘璁や笌鎸佷箙鍖栭棶棰橈紝鍚屾椂鍒嗕韩鎬ц兘鐩戞帶涓庢棩蹇楃鐞嗙殑鏈€浣冲疄璺点€傝鎴戜滑鍏卞悓鏈熷緟涓嬩竴绔犺妭鐨勭簿褰╁唴瀹瑰惂锛侌煂熲湪 鈥嬧€嬫湡寰呬綘鐨勫弬涓庯紒涓€璧锋帰绱abbitMQ鐨勪笘鐣屽惂锛佽鎴戜滑鍏卞悓瑙佽瘉浣犵殑鎴愰暱涓庤繘姝ワ紒馃専鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄢ湪鉁ㄣ€? 锛堢敱浜庣瘒骞呰繃闀匡紝宸茬渷鐣ラ儴鍒嗙粏鑺傦紝灏嗗湪鍚庣画绔犺妭璇︾粏灞曞紑銆傦級 鈥嬧€嬫湡寰呬綘鐨勫叧娉ㄤ笌鍙備笌锛佷竴璧峰紑鍚繖鍦虹簿褰╃殑RabbitMQ鍐掗櫓涔嬫梾鍚э紒馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専馃専锛佽缁х画鍏虫敞鎴戜滑鍚庣画鐨勬洿鏂板摝锛佹劅璋㈡敮鎸侊紒鉂わ笍馃檹
文章来自《钓虾网小编|www.jnqjk.cn》整理于网络,文章内容不代表本站立场,转载请注明出处。