本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例4: CommitIfNecessary
public static void CommitIfNecessary(IModel channel)
{
AssertUtils.ArgumentNotNull(channel, "Channel must not be null");
channel.TxCommit();
}