RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统。它可以用于大型软件系统各个模块之间的高效通信,支持高并发,支持可扩展。
前提是你的RabbitMq服务已搭建好,制作一个winform窗体如图
入队列(生产者):
ServerAddress = this.ServerAddress.Text.Trim(),
VirtualHost = this.VirtualHost.Text.Trim(),
UserName = this.UserName.Text.Trim(),
Password = this.Password.Text.Trim(),
Exchange = this.Exchange.Text.Trim(),
ExchangeType = "direct",
RoutingKey = this.RoutingKey.Text.Trim()
};
RabbitProducer rp = new RabbitProducer(rpc);
rp.ProduceMessage("1", this.QueueName.Text.Trim());
rpc = null;
this.label8.Text = "发送" + this.QueueName.Text.Trim() + "队列数据成功";
出队列(消费者):
RabbitConsumerConfig rcc = new RabbitConsumerConfig()
{
ServerAddress = this.ServerAddress.Text.Trim(),
VirtualHost = this.VirtualHost.Text.Trim(),
UserName = this.UserName.Text.Trim(),
Password = this.Password.Text.Trim()
};
RabbitConsumer rc = new RabbitConsumer(rcc);
rc.ConsumeMessage(GetQueue, this.QueueName.Text.Trim());
这只是模仿了生产者和消费者,如果产生错误队列该怎么办?欲知后事如何,请听下次分享。。。。