예제 #1
0
        public static void send()
        {
            MessageQueue MQ = new MessageQueue(".\\private$\\TestQueue");
            //MQ.Send("消息测试", "测试消息");
            OrderStruct model = new OrderStruct();

            model.NickName     = "你好呀阿道夫上的";
            model.SupplierName = "哈哈";
            //MQ.Send(model);
            Message message = new Message();

            message.Label = "消息lable";
            message.Body  = model;
            //MQ.Send(message);
            MSMQManager.Instance.Send(model);
            Console.WriteLine("结束");
        }
예제 #2
0
        protected static void receiveSimpleMsg()
        {
            MessageQueue MQ = new MessageQueue(@".\private$\ordertest");

            //调用MessageQueue的Receive方法接收消息
            if (MQ.GetAllMessages().Length > 0)
            {
                MQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(ConsoleApplication1.OrderStruct) });
                System.Messaging.Message message = MQ.Receive();
                if (message != null)
                {
                    //message.Formatter = new System.Messaging.XmlMessageFormatter(new string[] { "Message.Bussiness.VideoPath,Message" });//消息类型转换

                    OrderStruct data = (OrderStruct)message.Body;
                    //Console.WriteLine(string.Format("接收消息成功,lable:{0},body:{1},{2}<br/>", message.Label, data.NickName, DateTime.Now));
                    Console.WriteLine("商品名称" + data.NickName);
                }
            }
            else
            {
                Console.WriteLine("没有消息了!<br/>");
            }
        }