Example #1
0
        //事务消息的发送和接收
        public void Show2()
        {
            //发送 事务消息
            string queuePath = @".\private$\lxfSW";

            QueueManger.Createqueue(queuePath, true);
            //MessageQueueTransaction myTransaction = new MessageQueueTransaction();
            //myTransaction.Begin();
            //Student stu1 = new Student(){Name="张三",Age=21};
            //Student stu2 = new Student(){Name="历史",Age=27};
            //List<Student> list = new List<Student>();
            //list.Add(stu1);
            //list.Add(stu2);
            //bool isPass = QueueManger.SendMessage<List<Student>>(list, queuePath, myTransaction);
            //myTransaction.Commit();
            //MessageBox.Show(isPass.ToString());

            //接收 事务消息
            //string sMessage = string.Empty;
            //MessageQueueTransaction myTransaction = new MessageQueueTransaction();
            //myTransaction.Begin();
            //List<Student> listB = QueueManger.ReceiveMessage<List<Student>>(queuePath, myTransaction);
            //foreach(Student s in listB)
            //{
            //    sMessage += s.Name + ",";
            //}
            //myTransaction.Commit();
            //MessageBox.Show(sMessage);
        }
Example #2
0
        //将邮件信息发送到消息队列中
        private void btnSend_Click(object sender, EventArgs e)
        {
            MailInfo mi = new MailInfo();

            mi.StmpServer     = txtSMTP.Text.Trim();
            mi.SendAddress    = txtFJRDZ.Text.Trim();
            mi.SendPwd        = txtFJRMM.Text.Trim();
            mi.ReceiveAddress = txtSJRDZ.Text.Trim();
            mi.Title          = txtYJZT.Text.Trim();
            mi.Content        = txtYJZW.Text.Trim();
            if (mi != null)
            {
                string queuePath = @".\private$\lxfMail";

                bool isPass = QueueManger.Createqueue(queuePath);//创建队列
                if (isPass == true)
                {
                    isPass = QueueManger.SendMessage <MailInfo>(mi, queuePath);//发送消息到队列
                    if (isPass == true)
                    {
                        MessageBox.Show("成功");
                    }
                    else
                    {
                        MessageBox.Show("失败");
                    }
                }
            }
        }
Example #3
0
        //异步消息队列
        public void Show3()
        {
            //发送消息
            string queuePath = @".\private$\lxfAsync";
            MessageQueueTransaction myTransaction = new MessageQueueTransaction();

            QueueManger.Createqueue(queuePath, true);
            Student stuM = new Student()
            {
                Name = "KKM", Age = 29
            };

            myTransaction.Begin();
            QueueManger.SendMessage <Student>(stuM, queuePath, myTransaction);
            myTransaction.Commit();

            //异步接收消息
            MessageQueueTransaction myTransactionB = new MessageQueueTransaction();
            MessageQueue            myQueue        = new MessageQueue(queuePath);

            myQueue.ReceiveCompleted += new ReceiveCompletedEventHandler(MyReceiveCompleted);
            myQueue.Formatter         = new XmlMessageFormatter(new Type[] { typeof(Student) });
            myTransactionB.Begin();
            myQueue.BeginReceive();
            myTransactionB.Commit();
        }
Example #4
0
        //http://www.cnblogs.com/shaoshun/p/3800655.html
        //http://dev.yesky.com/229/8196229_2.shtml
        //消息队列 创建 发送 获取 及 事务
        public void Show()
        {
            string queuePath = @".\private$\lxf";
            bool   isPass    = QueueManger.Createqueue(queuePath);//创建队列

            if (isPass == true)
            {
                Student student = new Student();
                student.Name = "風2014";
                student.Age  = 25;
                isPass       = QueueManger.SendMessage <Student>(student, queuePath);//发送消息到队列
                if (isPass == true)
                {
                    //Student s = QueueManger.ReceiveMessageByPeek<Student>(queuePath);//采用Peek方法接收消息
                    //Student s = QueueManger.ReceiveMessage<Student>(queuePath);//采用Receive方法来接收消息
                    //MessageBox.Show(s.Name);

                    MessageQueueTransaction tran = new MessageQueueTransaction();
                    tran.Begin();
                    try
                    {
                        Student stu;
                        for (int i = 0; i < 4; i++)
                        {
                            stu = new Student()
                            {
                                Name = "shaoshun" + i, Age = i
                            };
                            QueueManger.SendMessage <Student>(stu, queuePath, tran);
                            if (i == 3)
                            {
                                throw new Exception();
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        tran.Abort();
                    }
                }
            }

            //MessageBox.Show(isPass.ToString());
        }