easyNetq demo
2021-06-30 21:05
标签:summary name route show nec public 类库 新建 color 本demo包含一个类库,2个console程序 1.新建类库 MQHelper,控制台程序 consumer和proc ,控制台程序引用MQHelper 2.使用nuget安装easynwtq 和rabbitmq.client.dll ,执行 3.MQHelper 4.proc 生产程序 5.consumer 消费程序 6.先bin/debug 里先打开 consumer.exe ,再打开proc.exe 就能看到效果了 easyNetq demo 标签:summary name route show nec public 类库 新建 color 原文地址:http://www.cnblogs.com/tiancai/p/7135775.htmlInstall-Package EasyNetQ -Version 1.1.3.500
会自动安装 easynwtq和依赖项rabbitmq.client.dll using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EasyNetQ;
namespace MQHelper
{
public class MQManage
{
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace proc
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("proc2");
//// 创建消息bus
while (true)
{
MQHelper.MQManage.Publish(new MQHelper.MyMessage
{
MessageID = "2",
MessageRouter = "ro2",
MessageBody ="当前时间="+DateTime.Now.ToString(),
MessageTitle = "title" + DateTime.Now
});
Thread.Sleep(3000);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace consumer
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("consumer2");
//// 创建消息bus
MQHelper.MQManage.Subscribe(new MQHelper.MyMessage
{
MessageID = "2",
MessageRouter = "ro2"
//MessageBody=DateTime.Now.ToString(),
//MessageTitle="title"+DateTime.Now
});
}
}
}