本文整理汇总了C#中IModel.TxSelect方法的典型用法代码示例。如果您正苦于以下问题:C# IModel.TxSelect方法的具体用法?C# IModel.TxSelect怎么用?C# IModel.TxSelect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IModel
的用法示例。
在下文中一共展示了IModel.TxSelect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Open
public override void Open(TimeSpan timeout)
{
if (State != CommunicationState.Created && State != CommunicationState.Closed)
throw new InvalidOperationException(string.Format("Cannot open the channel from the {0} state.", State));
OnOpening();
#if VERBOSE
DebugHelper.Start();
#endif
_model = ConnectionManager.Instance.OpenModel(new RabbitMQUri(RemoteAddress.Uri), _bindingElement.BrokerProtocol, timeout);
if (Transaction.Current != null)
{
_model.TxSelect();
_transactional = true;
}
if (_messageProcessor != null)
{
_model.BasicReturn += ModelOnBasicReturn;
}
#if VERBOSE
DebugHelper.Stop(" ## Out.Open {{Time={0}ms}}.");
#endif
OnOpened();
}
示例2: ReceiveInContext
public IMessage ReceiveInContext (ref string host, ref IConnection cn,
ref IModel model, string txId)
{
if (host == null)
host = q.QRef.Host;
else if (host != q.QRef.Host)
throw new MonoMessagingException ("Transactions can not span multiple hosts");
if (cn == null) {
ConnectionFactory cf = new ConnectionFactory ();
cn = cf.CreateConnection (host);
}
if (model == null) {
model = cn.CreateModel ();
model.TxSelect ();
}
return doReceive (q, model);
}
示例3: SendInContext
private void SendInContext (ref string host, ref IConnection cn,
ref IModel model, IMessage msg, string txId)
{
if (host == null)
host = QRef.Host;
else if (host != QRef.Host)
throw new MonoMessagingException ("Transactions can not span multiple hosts");
if (cn == null) {
ConnectionFactory cf = new ConnectionFactory ();
cn = cf.CreateConnection (host);
}
if (model == null) {
model = cn.CreateModel ();
model.TxSelect ();
}
SetDeliveryInfo (msg, GetVersion (cn), txId);
Send (model, msg);
}
示例4: DeclareTransactional
/// <summary>
/// Declare to that broker that a channel is going to be used transactionally, and convert exceptions that arise.
/// </summary>
/// <param name="channel">
/// The channel to use.
/// </param>
/// <exception cref="SystemException">
/// </exception>
public static void DeclareTransactional(IModel channel)
{
try
{
channel.TxSelect();
}
catch (Exception e)
{
throw RabbitUtils.ConvertRabbitAccessException(e);
}
}
示例5: 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;
}
示例6: 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;
}