一、下載rabbitmq
http://www.rabbitmq.com/install-windows.html
二、下載otp
http://www.erlang.org/downloads
三、安裝otp、rabbitmq
四、配置rabbitmq
找到bat的目錄
執行相關命令
1.添加用戶密碼 rabbitmqctl add_user wenli wenli
2.設置wenli為管理員rabbitmqctl set_user_tags wenli administrator
3.啟動rabbitmq的web管理rabbitmq-plugins enable rabbitmq_management
4.創建virtual host
5.設置用戶權限
點擊用戶名進行設置
將virtual hosts 權限賦給用戶wenli
6.創建exchanges
五.創建c# console
1.下載rabbitmq驅動 https://github.com/yswenli/wenli.data.rabbitmq/releases/tag/release1.0.0
2.添加引用
3.添加配置
4.測試代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
using system; using system.text; using system.threading; using system.threading.tasks; namespace wenli.data.rabbitmq.console { using console = system.console; class program { static void main( string [] args) { console.title = "wenli.data.rabbitmq.console" ; console.writeline( "正連接到mq" ); try { test(); } catch (exception ex) { console.writeline( "err:" + ex.message + ex.source + ex.stacktrace); } console.read(); } static void test() { var topic = "testtopic" ; var cnn = rabbitmqbuilder. get (mqconfig. default ).getconnection(); var operation = cnn.getoperation(topic); console.writeline( "正連接到訂閱【" + topic + "】" ); operation.subscribe(); console.writeline( "正在入隊" ); task.factory.startnew(() => { while ( true ) { operation.enqueue(encoding.utf8.getbytes(datetime.now.tostring( "yyyy-mm-dd hh:mm:ss.fff" ) + " hello!" )); thread.sleep(1); } }); console.writeline( "正在出隊" ); task.factory.startnew(() => { while ( true ) { var result = operation.dnqueue(); if (result == null ) { thread.sleep(1); } else { console.writeline(encoding.utf8.getstring(result)); } } }); console.readline(); console.writeline( "正在取消訂閱" ); operation.unsubscribe(); console.writeline( "測試完成" ); } } } |
5.運行結果:
至此c# 成功操作rabbitmq完成。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/yswenli/archive/2017/08/29/7446919.html