当前位置: 首页>>代码示例>>C#>>正文


C# MessageQueueTransaction.Commit方法代码示例

本文整理汇总了C#中System.Messaging.MessageQueueTransaction.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# MessageQueueTransaction.Commit方法的具体用法?C# MessageQueueTransaction.Commit怎么用?C# MessageQueueTransaction.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Messaging.MessageQueueTransaction的用法示例。


在下文中一共展示了MessageQueueTransaction.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnAdd_Click

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            string queueName = ConfigurationManager.AppSettings["MSMQLocation"];

            MessageQueue rmTxnQ = new MessageQueue(queueName);

            rmTxnQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(ProcessMessage) });

            foreach (ListBoxItem itm in files.Items)
            {
                MessageQueueTransaction msgTx = new MessageQueueTransaction();
                msgTx.Begin();
                try
                {
                    string argument = "-i \"{0}\" -o \"{1}\" --preset \"" + ConfigurationManager.AppSettings["HandbrakePreset"] + "\"";

                    string destination = txtDestination.Text + "\\" + System.IO.Path.GetFileNameWithoutExtension(itm.ToolTip.ToString()) + ".m4v";

                    ProcessMessage p = new ProcessMessage() { CommandLine = argument, DestinationURL = destination, OrignalFileURL = itm.ToolTip.ToString() };

                    rmTxnQ.Send(p, msgTx);
                    results.Items.Insert(0, string.Format("{0} added to queue", p.OrignalFileURL));

                    msgTx.Commit();
                }
                catch (Exception ex)
                {
                    results.Items.Insert(0, ex.Message);
                    msgTx.Abort();
                }
            }
        }
开发者ID:tiernano,项目名称:HandbrakeCluster,代码行数:32,代码来源:MainWindow.xaml.cs

示例2: ReceiveMessage

        public override async Task ReceiveMessage()
        {
            Message message = null;

            try
            {
                using (var msmqTransaction = new MessageQueueTransaction())
                {
                    msmqTransaction.Begin();

                    if (!TryReceive(msmqTransaction, out message))
                    {
                        return;
                    }

                    Dictionary<string, string> headers;

                    if (!TryExtractHeaders(message, out headers))
                    {
                        MovePoisonMessageToErrorQueue(message, msmqTransaction);

                        msmqTransaction.Commit();
                        return;
                    }

                    var shouldCommit = await ProcessMessage(msmqTransaction, message, headers).ConfigureAwait(false);

                    if (shouldCommit)
                    {
                        msmqTransaction.Commit();
                    }
                    else
                    {
                        msmqTransaction.Abort();
                    }
                }
            }
            // We'll only get here if Commit/Abort/Dispose throws which should be rare.
            // Note: If that happens the attempts counter will be inconsistent since the message might be picked up again before we can register the failure in the LRU cache.
            catch (Exception exception)
            {
                if (message == null)
                {
                    throw;
                }

                failureInfoStorage.RecordFailureInfoForMessage(message.Id, exception);
            }
        }
开发者ID:Particular,项目名称:NServiceBus,代码行数:49,代码来源:SendsAtomicWithReceiveNativeTransactionStrategy.cs

示例3: Run

        void Run()
        {
            MessageQueueTransaction transaction = new MessageQueueTransaction();
            while (!shouldStop)
            {
                try
                {
                    transaction.Begin();
                    Message message = requestQueue.Receive(new TimeSpan(0, 0, 1), transaction);

                    responseQueue.Send(message, transaction);
                    transaction.Commit();

                    synchronizedInvoke.BeginInvoke(addMessage, new object[] { requestQueueName, message });
                }
                catch (MessageQueueException e)
                {
                    if (e.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
                        Console.WriteLine("Receive failure on " + requestQueueName + " " + e.StackTrace,
                            System.Diagnostics.EventLogEntryType.Error);
                }
                finally
                {
                    if (transaction.Status == MessageQueueTransactionStatus.Pending)
                    {
                        transaction.Abort();
                    }
                }
            }
        }
开发者ID:untoldwind,项目名称:soatools,代码行数:30,代码来源:MessageListener.cs

示例4: Run

        static void Run()
        {
            MessageQueue queue = null;
            MessageQueueTransaction trans = null;
            try
            {
                queue = new MessageQueue();
                queue.Path = Constants.QUEUE_PATH;
                queue.DefaultPropertiesToSend.Recoverable = true;

                trans = new MessageQueueTransaction();
                trans.Begin();

                MyOrder order = new MyOrder();
                order.ID = DateTime.Now.Ticks.ToString();
                order.Name = "Order_" + order.ID;

                Message msg = new Message(order);

                queue.Send(msg, trans);
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Abort();
            }
            finally
            {
                queue.Close();
            }

            Console.WriteLine("message sent..");
        }
开发者ID:yoshiao,项目名称:WCF_Samples,代码行数:33,代码来源:Program.cs

示例5: Main

        private static void Main(string[] args)
        {
            const string message = "Testing MSMQ";

            List<MessageQueue> queues = CreateQueues(".\\private$\\FirstQueue",
                ".\\private$\\SecondQueue",
                ".\\private$\\ThirdQueue");

            var sender = new Sender();
            var receiver = new Receiver();

            /*
             * Send to all the queues within a transaction
             */
            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();

                foreach (MessageQueue queue in queues)
                {
                    sender.Send(queue, message, transaction);
                }

                transaction.Commit();
            }

            /*
             * Read from all the queues
             */
            receiver.StartReading(queues);

            Console.ReadKey();
        }
开发者ID:MarcusParkkinen,项目名称:MSMQTransactionsExample,代码行数:33,代码来源:Program.cs

示例6: GetMessageFromQueue

		public override void GetMessageFromQueue(string messageId, MessageQueue queue, Action<Message> processMethod)
		{
			using (var transaction = new MessageQueueTransaction())
			{
				transaction.Begin();
				Logger.DebugFormat("Transaction for {0} started.", messageId);

				Message message;
				try
				{
					message = queue.ReceiveById(messageId, TimeSpan.FromSeconds(30), transaction);
					Logger.DebugFormat("Message with id {0} received.", messageId);
				}
				catch (Exception ex)
				{
					transaction.Abort();
					Logger.Error(
						string.Concat("Failed to receive message with id ", messageId, "transactions aborted.")
						, ex);
					return;
				}

				if (message != null)
				{
					processMethod(message);
				}

				if (transaction.Status != MessageQueueTransactionStatus.Aborted)
					transaction.Commit();
			}
		}
开发者ID:mickednk,项目名称:MightyLittle.MQ,代码行数:31,代码来源:TransactionalReceive.cs

示例7: Send

        public void Send(Object message)
        {
            // Open the queue.
            using (var queue = new MessageQueue(_queueName.GetQueueFormatName()))
            {
                // Set the formatter to JSON.
                queue.Formatter = new MsmqMessageFormatter();

                // Since we're using a transactional queue, make a transaction.
                using (MessageQueueTransaction mqt = new MessageQueueTransaction())
                {
                    mqt.Begin();

                    // Create a simple text message.
                    Message myMessage = new Message(message, new MsmqMessageFormatter());
                    myMessage.Label = message.GetType().FullName;
                    myMessage.ResponseQueue = new MessageQueue(_queueName.GetQueueFormatName());

                    // Send the message.
                    queue.Send(myMessage, mqt);

                    mqt.Commit();
                }
            }
        }
开发者ID:paralect,项目名称:Paralect.ServiceBus,代码行数:25,代码来源:MsmqQueue.cs

示例8: MangledMessageIsNotReceived

        public void MangledMessageIsNotReceived()
        {
            using (var messageQueue = new MessageQueue(MsmqUtil.GetPath(_inputQueueName)))
            {
                var transaction = new MessageQueueTransaction();
                transaction.Begin();
                messageQueue.Send(new Message
                {
                    Extension = Encoding.UTF32.GetBytes("this is definitely not valid UTF8-encoded JSON")
                }, transaction);
                transaction.Commit();
            }

            Thread.Sleep(5000);

            CleanUpDisposables();

            using (var messageQueue = new MessageQueue(MsmqUtil.GetPath(_inputQueueName)))
            {
                messageQueue.MessageReadPropertyFilter = new MessagePropertyFilter
                {
                    Extension = true
                };

                var transaction = new MessageQueueTransaction();
                transaction.Begin();

                var message = messageQueue.Receive(transaction);

                Assert.That(message, Is.Not.Null);
                Assert.That(Encoding.UTF32.GetString(message.Extension), Is.EqualTo("this is definitely not valid UTF8-encoded JSON"));

                transaction.Commit();
            }
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:35,代码来源:TestMsmqMangledMessage.cs

示例9: Send2WithTransaction

		public void Send2WithTransaction ()
		{
			Message sent1 = new Message ("Message 1", new BinaryMessageFormatter ());
			Message sent2 = new Message ("Message 2", new BinaryMessageFormatter ());
			MessageQueue mq = MQUtil.GetQueue (MQUtil.CreateQueueName (), true);
			mq.MessageReadPropertyFilter.SetAll ();
			Assert.IsTrue (mq.Transactional, "Message Queue should be transactional");
			using (MessageQueueTransaction tx = new MessageQueueTransaction ()) {
				tx.Begin ();
				
				mq.Send (sent1, tx);
				mq.Send (sent2, tx);
				
				tx.Commit ();
				
				Message received1 = mq.Receive ();
				Assert.IsNotNull (received1.TransactionId, "TransactionId not set");
				Message received2 = mq.Receive ();
				Assert.IsNotNull (received2.TransactionId, "TransactionId not set");
				
				Assert.AreEqual (received1.TransactionId, received2.TransactionId, "Messages have differing TransactionIds");
				Assert.IsTrue (received1.TransactionId.Length > 1);
				Assert.AreEqual (sent1.Body, received1.Body, "Message 1 not delivered correctly");
				Assert.AreEqual (sent2.Body, received2.Body, "Message 2 not delivered correctly");
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:26,代码来源:TransactionMessagingTest.cs

示例10: MoveMessage

        static void MoveMessage(Message message, string destinationQueueName)
        {
            var sourceQueuePath = message.QueuePath;
            var destinationQueuePath = MsmqUtil.GetFullPath(destinationQueueName);

            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();
                try
                {
                    var sourceQueue = new MessageQueue(sourceQueuePath) {MessageReadPropertyFilter = DefaultFilter()};
                    var destinationQueue = new MessageQueue(destinationQueuePath);

                    var msmqMessage = sourceQueue.ReceiveById(message.Id, transaction);
                    destinationQueue.Send(msmqMessage, transaction);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Abort();
                    throw;
                }
            }

            Messenger.Default.Send(new MessageMoved(message, sourceQueuePath, destinationQueuePath));
        }
开发者ID:sTodorov,项目名称:Rebus,代码行数:27,代码来源:MsmqInteraction.cs

示例11: _orderQueue_PeekCompleted

        static void _orderQueue_PeekCompleted(object sender, PeekCompletedEventArgs e)
        {
            var orderQueue = (MessageQueue)sender;

            var transaction = new MessageQueueTransaction();
            transaction.Begin();

            Order order;

            try
            {
                var receivedMessage = orderQueue.Receive(transaction);
                receivedMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });

                order = Order.DeserializeXml(receivedMessage.Body.ToString());

                using (var db = new OrderContext())
                {
                    db.Orders.Add(order);
                    db.SaveChanges();
                }

                transaction.Commit();
            }
            catch
            {
                // TODO: Log something
                transaction.Abort();
            }
            finally
            {
                orderQueue.BeginPeek();
            }
        }
开发者ID:sconno05,项目名称:order-service,代码行数:34,代码来源:Program.cs

示例12: sendDeclMessage

        public Boolean sendDeclMessage(string messageId, string outId, int sendType, string messageDetail, int place)
        {
            if (messageId == null && messageId == ""
                && outId == null && outId == ""
                && messageDetail == null && messageDetail == ""
                && sendType == 0
                && place == 0)
            {
                return false;
            }
            MessageQueueTransaction msgTransaction = new MessageQueueTransaction();

            try
            {
                mq = mqFactory.CreateMsgQueueFactory(sendType, place);

                using (TransactionScope scope = new TransactionScope())
                {

                    msgTransaction.Begin();
                    XmlDocument xmldoc = new XmlDocument();

                    if (place == (int)SendPlace.GOVERNMENT)
                    {

                        String key = configUtil.getGovPwd();
                        messageDetail = AESUtil.AesEncoding(messageDetail, key, Encoding.UTF8);

                        mq.SendEncryptMessage(messageDetail, msgTransaction, messageId);
                    }
                    else
                    {
                        xmldoc.LoadXml(messageDetail);
                        mq.SendMessage(xmldoc, msgTransaction, messageId);
                    }
                    Logger.Debug(messageDetail);

                    messageDeclService.createDeclMessage(messageId, outId, sendType, messageDetail,place);
                    messageRespService.createResponseMessage(messageId, outId, sendType,place);

                    scope.Complete();
                    msgTransaction.Commit();
                    return true;

                }
            } catch (Exception e)
            {
                msgTransaction.Abort();
                if ((int)CustomsDeclarationProxy.Constant.CustomsMessageType.MANIFEST== sendType)
                {
                    Logger.Error("shipmentPackId:" + outId + "send and insert manifest message failed!", e);
                }
                else if ((int)CustomsDeclarationProxy.Constant.CustomsMessageType.ORDER == sendType)
                {
                    Logger.Error("shipmentPackId:" + outId + "send and insert order message failed!", e);
                }
                return false;
            }
        }
开发者ID:huangkungit,项目名称:msmq-example,代码行数:59,代码来源:DeclareProxyAPI.cs

示例13: btnR_Click

 private void btnR_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.chbChoose1.Checked)
         {
             MessageQueue queue = new MessageQueue(this.txtMSMQ1.Text) {
                 Formatter = new BinaryMessageFormatter()
             };
             System.Messaging.Message message = new System.Messaging.Message();
             MessageQueueTransaction transaction = new MessageQueueTransaction();
             transaction.Begin();
             try
             {
                 message = queue.Receive(TimeSpan.FromMilliseconds(500.0), transaction);
             }
             catch
             {
                 transaction.Commit();
             }
             StreamReader reader = new StreamReader(message.BodyStream, Encoding.ASCII);
             if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 this.txtPath1.Text = this.saveFileDialog1.FileName;
                 FileStream output = new FileStream(this.txtPath1.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                 BinaryWriter writer = new BinaryWriter(output);
                 writer.Write(Encoding.Default.GetBytes(reader.ReadToEnd()));
                 writer.Flush();
                 writer.Close();
                 transaction.Commit();
                 MessageBox.Show("发送成功!");
             }
         }
         else
         {
             MessageQueue queue2 = new MessageQueue(this.txtMSMQ1.Text) {
                 Formatter = new BinaryMessageFormatter()
             };
             System.Messaging.Message message2 = new System.Messaging.Message();
             StreamReader reader2 = new StreamReader(queue2.Receive(TimeSpan.FromMilliseconds(500.0)).BodyStream, Encoding.ASCII);
             if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 this.txtPath1.Text = this.saveFileDialog1.FileName;
                 FileStream stream2 = new FileStream(this.txtPath1.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                 BinaryWriter writer2 = new BinaryWriter(stream2);
                 writer2.Write(Encoding.Default.GetBytes(reader2.ReadToEnd()));
                 writer2.Flush();
                 writer2.Close();
                 MessageBox.Show("发送成功!");
             }
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("发送失败!原因:" + exception.Message);
     }
 }
开发者ID:jimlong45,项目名称:msmqTool,代码行数:57,代码来源:Form1.cs

示例14: EnqueueJobId

 public static void EnqueueJobId(string queue, string jobId)
 {
     using (var messageQueue = CleanMsmqQueueAttribute.GetMessageQueue(queue))
     using (var message = new Message { Body = jobId, Label = jobId, Formatter = new BinaryMessageFormatter() })
     using (var transaction = new MessageQueueTransaction())
     {
         transaction.Begin();
         messageQueue.Send(message, transaction);
         transaction.Commit();
     }
 }
开发者ID:GitHuang,项目名称:Hangfire,代码行数:11,代码来源:MsmqUtils.cs

示例15: Send

		public override void Send(params object[] messages)
		{
			using (var transaction = new MessageQueueTransaction())
			{
				transaction.Begin();
				foreach (var message in messages)
				{
					Queue.Send(message, transaction);
				}
				transaction.Commit();
			}
		}
开发者ID:mickednk,项目名称:MightyLittle.MQ,代码行数:12,代码来源:Transactional.cs


注:本文中的System.Messaging.MessageQueueTransaction.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。