安装ErLang运行环境
配置运行环境变量
启动服务
地址在:complete-rabbitmq-bundle-1.7.0\rabbitmq-server-windows-1.7.0\rabbitmq_server-1.7.0\sbin
一段实例代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using RabbitMQ.Client; namespace rabbits { public partial class Form1 : Form { public Form1() { InitializeComponent(); } IConnection conn; IModel channel; private void button1_Click(object sender, EventArgs e) { conn = new ConnectionFactory().CreateConnection(Protocols.DefaultProtocol, this.textBox1.Text); channel = conn.CreateModel(); channel.ExchangeDeclare(this.textBox2.Text, ExchangeType.Direct); channel.QueueDeclare(this.textBox3.Text); channel.QueueBind(this.textBox3.Text, this.textBox2.Text, "", false, null); } private void button2_Click(object sender, EventArgs e) { byte[] message = System.Text.Encoding.UTF8.GetBytes(this.richTextBox1.Text); IBasicProperties props = channel.CreateBasicProperties(); props.ContentType = "text/plain"; props.DeliveryMode = 2; channel.BasicPublish(this.textBox2.Text, "", props, message); } private void button3_Click(object sender, EventArgs e) { bool noask = false; BasicGetResult result = channel.BasicGet(this.textBox3.Text, noask); if (result == null) { } else { IBasicProperties props = result.BasicProperties; byte[] body = result.Body; this.richTextBox2.Text = System.Text.Encoding.UTF8.GetString(body); channel.BasicAck(result.DeliveryTag, false); } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (this.channel != null && this.channel.IsOpen) { this.channel.Dispose(); } if (this.conn != null && this.conn.IsOpen) { this.conn.Dispose(); } } } }
冯瑞涛