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


C# IModel.TxCommit方法代码示例

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


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

示例1: CommitIfNecessary

 /// <summary>
 /// Commit the transaction if necessary.
 /// </summary>
 /// <param name="channel">
 /// The channel.
 /// </param>
 /// <exception cref="AmqpException">
 /// </exception>
 /// <exception cref="AmqpIOException">
 /// </exception>
 public static void CommitIfNecessary(IModel channel)
 {
     AssertUtils.ArgumentNotNull(channel, "Channel must not be null");
     try
     {
         channel.TxCommit();
     }
     catch (OperationInterruptedException oiex)
     {
         throw new AmqpException("An error occurred committing the transaction.", oiex);
     }
     catch (IOException ioex)
     {
         throw new AmqpIOException("An error occurred committing the transaction.", ioex);
     }
 }
开发者ID:DonMcRae,项目名称:spring-net-amqp,代码行数:26,代码来源:RabbitUtils.cs

示例2: EnsureThreadBoundModelIsInitialized

        void EnsureThreadBoundModelIsInitialized(ITransactionContext context)
        {
            if (threadBoundModel != null && threadBoundModel.IsOpen)
            {
                if (context[CurrentModelKey] == null)
                {
                    context[CurrentModelKey] = threadBoundModel;
                    context.DoCommit += () => threadBoundModel.TxCommit();
                    context.DoRollback += () => threadBoundModel.TxRollback();
                }
                return;
            }

            threadBoundModel = GetConnection().CreateModel();
            threadBoundModel.TxSelect();

            context.DoCommit += () => threadBoundModel.TxCommit();
            context.DoRollback += () => threadBoundModel.TxRollback();

            // ensure any sends withing this transaction will use the thread bound model
            context[CurrentModelKey] = threadBoundModel;
        }
开发者ID:rasmuskl,项目名称:Rebus,代码行数:22,代码来源:RabbitMqMessageQueue.cs

示例3: PublishTransactionalMessages

        private TimeSpan PublishTransactionalMessages(IModel transactionalChannel, string hostname, string exchange, string path, bool requeue)
        {
            TimeSpan result = TimeSpan.MaxValue;
            MessageFormatter messageFormatter = new MessageFormatter();
            string[] files = Directory.GetFiles(path, "*.msg");
            int skipCount = 0;
            while (files.Length > skipCount)
            {
                skipCount = 0;
                foreach (string item in files)
                {
                    if (File.Exists(item))
                    {
                        byte[] data = null;
                        try
                        {
                            data = File.ReadAllBytes(item);
                        }
                        catch
                        {

                        }
                        if (data != null)
                        {
                            if (requeue)
                            {
                                ServiceEventMessage message = messageFormatter.Deserialise(new MemoryStream(data));
                                if ((message != null) && (message.QueueAfterTime.HasValue) && (message.QueueAfterTime.Value > DateTime.UtcNow))
                                {
                                    TimeSpan delay = message.QueueAfterTime.Value.Subtract(DateTime.UtcNow);
                                    if (delay < result)
                                        result = delay;
                                    skipCount++;
                                    continue;
                                }
                            }
                            string messageFilename = Path.ChangeExtension(item, ".trx");
                            if (File.Exists(messageFilename))
                                DeleteMessageFile(messageFilename);
                            File.Move(item, messageFilename);
                            IBasicProperties properties = transactionalChannel.CreateBasicProperties();
                            properties.CorrelationId = hostname;
                            properties.DeliveryMode = 2;
                            properties.ContentType = messageFormatter.ContentType;
                            string filename = Path.GetFileNameWithoutExtension(item);
                            string routingKey = string.Empty;
                            int index = filename.IndexOf('_');
                            if (index != -1)
                            {
                                routingKey = filename.Substring(0, index);
                                int nextIndex = filename.IndexOf('_', index + 1);
                                if (nextIndex == -1)
                                    properties.MessageId = filename.Substring(index + 1);
                                else
                                    properties.MessageId = filename.Substring(index + 1, nextIndex - index - 1);
                            }
                            transactionalChannel.TxSelect();
                            transactionalChannel.BasicPublish(exchange, routingKey, properties, data);
                            transactionalChannel.TxCommit();
                            DeleteMessageFile(messageFilename);
                        }
                    }
                }
                files = Directory.GetFiles(path, "*.msg");
            }
            return result;
        }
开发者ID:CreatorDev,项目名称:DeviceServer,代码行数:67,代码来源:DALRabbitMQ.cs

示例4: CommitIfNecessary

 public static void CommitIfNecessary(IModel channel)
 {
     AssertUtils.ArgumentNotNull(channel, "Channel must not be null");
     channel.TxCommit();
 }
开发者ID:moprise,项目名称:spring-net-amqp,代码行数:5,代码来源:RabbitUtils.cs


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