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);

                    }
                }
            }
        }

  

posted on 2016-11-29 16:19  高兴happy  阅读(279)  评论(0编辑  收藏  举报