RabbitMQ消息机制单人分发

 static void Main(string[] args)
{ // More.SendMessage(); var factory = new ConnectionFactory();
factory.HostName = "192.168.1.117";
factory.UserName = "witbank";
factory.Password = "123456"; using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("hello", false, false, false, null);
while (true)
{
string message = "请输入要发送的信息"; Console.WriteLine(message);
message = Console.ReadLine();
var properties = channel.CreateBasicProperties();
properties.DeliveryMode = 2;
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish("", "hello", null, body);
Console.WriteLine(" set {0}", message);
}
}
}
}

  

   static void Main(string[] args)
{
// More.ReceiveMessage(); var factory = new ConnectionFactory();
factory.HostName = "192.168.1.117";
factory.UserName = "witbank";
factory.Password = "123456"; using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("hello", false, false, false, null); var consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume("hello", true, consumer); Console.WriteLine(" waiting for message.");
while (true)
{
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue(); var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
Console.WriteLine("Received {0}", message); }
}
}
}

  

上一篇:【前端】JS文本比较插件


下一篇:JAVA Native Interface (JNI)