一、下载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