本文整理汇总了C#中IModel.ConfirmSelect方法的典型用法代码示例。如果您正苦于以下问题:C# IModel.ConfirmSelect方法的具体用法?C# IModel.ConfirmSelect怎么用?C# IModel.ConfirmSelect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IModel
的用法示例。
在下文中一共展示了IModel.ConfirmSelect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetActiveChannel
public void SetActiveChannel(IModel channel)
{
_deliveredAckDictionary = new ConcurrentDictionary<ulong, TaskCompletionSource<ulong>>();
_ackTimers = new ConcurrentDictionary<ulong, Timer>();
_channel = channel;
_channel.BasicAcks += (sender, args) =>
{
_logger.LogInformation($"Recieved ack for {args.DeliveryTag} with multiple set to '{args.Multiple}'");
if (args.Multiple)
{
for (var i = args.DeliveryTag; i > 0; i--)
{
CompleteConfirm(i);
}
}
else
{
CompleteConfirm(args.DeliveryTag);
}
};
_channel.FlowControl += (sender, args) =>
{
_logger.LogInformation($"The flow control event has been raised on channel '{_channel.ChannelNumber}'. Active: {args.Active}.");
};
channel.ConfirmSelect();
}
示例2: BeforePublishEnabled
public void BeforePublishEnabled(IModel publishModel)
{
publishModel.BasicAcks += PublishModelOnBasicAcks;
publishModel.BasicNacks += PublishModelOnBasicNacks;
publishModel.ConfirmSelect();
scheduler.Start();
}
示例3: OnChannelOpened
protected override void OnChannelOpened(IModel newModel)
{
// switch channel to confirms mode.
newModel.ConfirmSelect();
newModel.BasicAcks += ModelOnBasicAcks;
newModel.BasicNacks += ModelOnBasicNacks;
base.OnChannelOpened(newModel);
}
示例4: ConfirmsAwareChannel
public ConfirmsAwareChannel(IConnection connection, bool usePublisherConfirms, TimeSpan maxWaitTimeForConfirms)
{
this.usePublisherConfirms = usePublisherConfirms;
this.maxWaitTimeForConfirms = maxWaitTimeForConfirms;
Channel = connection.CreateModel();
if (usePublisherConfirms)
{
Channel.ConfirmSelect();
}
}
示例5: GetAckTask
public Task GetAckTask(IModel channel)
{
if (channel.NextPublishSeqNo == 0UL)
{
_logger.LogInformation($"Setting 'Publish Acknowledge' for channel '{channel.ChannelNumber}'");
channel.ConfirmSelect();
channel.BasicAcks += (sender, args) =>
{
var model = sender as IModel;
_logger.LogInformation($"Recieved ack for {args.DeliveryTag}/{model.ChannelNumber} with multiple set to '{args.Multiple}'");
if (args.Multiple)
{
for (var i = args.DeliveryTag; i > 0; i--)
{
CompleteConfirm(model, i, true);
}
}
else
{
CompleteConfirm(model, args.DeliveryTag);
}
};
}
var key = CreatePublishKey(channel, channel.NextPublishSeqNo);
var tcs = new TaskCompletionSource<ulong>();
if (!_deliveredAckDictionary.TryAdd(key, tcs))
{
_logger.LogWarning($"Unable to add delivery tag {key} to ack list.");
}
_ackTimers.TryAdd(key, new Timer(state =>
{
_logger.LogWarning($"Ack for {key} has timed out.");
TryDisposeTimer(key);
TaskCompletionSource<ulong> ackTcs;
if (!_deliveredAckDictionary.TryGetValue(key, out ackTcs))
{
_logger.LogWarning($"Unable to get TaskCompletionSource for {key}");
return;
}
ackTcs.TrySetException(new PublishConfirmException($"The broker did not send a publish acknowledgement for message {key} within {_publishTimeout.ToString("g")}."));
}, channel, _publishTimeout, new TimeSpan(-1)));
return tcs.Task;
}
示例6: RabbitMqModelContext
RabbitMqModelContext(ConnectionContext connectionContext, IModel model, IRabbitMqHost host, ITaskParticipant participant)
: base(new PayloadCacheScope(connectionContext))
{
_connectionContext = connectionContext;
_model = model;
_host = host;
_participant = participant;
_published = new ConcurrentDictionary<ulong, PendingPublish>();
_taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);
_model.ModelShutdown += OnModelShutdown;
_model.BasicAcks += OnBasicAcks;
_model.BasicNacks += OnBasicNacks;
_model.BasicReturn += OnBasicReturn;
if (host.Settings.PublisherConfirmation)
{
_model.ConfirmSelect();
}
_participant.SetReady();
}
示例7: ConfigureChannel
private IModel ConfigureChannel(IModel channel)
{
channel.ConfirmSelect();
return channel;
}
示例8: SetModel
private void SetModel(IModel model)
{
// we only need to set up the channel once, but the persistent channel can change
// the IModel instance underneath us, so check on each publish.
if (cachedModel == model) return;
if (cachedModel != null)
{
// the old model has been closed and we're now using a new model, so remove
// any existing callback entries in the dictionary
dictionary.Clear();
cachedModel.BasicAcks -= ModelOnBasicAcks;
cachedModel.BasicNacks -= ModelOnBasicNacks;
}
cachedModel = model;
// switch channel to confirms mode.
model.ConfirmSelect();
model.BasicAcks += ModelOnBasicAcks;
model.BasicNacks += ModelOnBasicNacks;
}
示例9: AssertQueueRecovery
protected void AssertQueueRecovery(IModel m, string q, bool exclusive)
{
m.ConfirmSelect();
m.QueueDeclarePassive(q);
QueueDeclareOk ok1 = m.QueueDeclare(q, false, exclusive, false, null);
Assert.AreEqual(ok1.MessageCount, 0);
m.BasicPublish("", q, null, encoding.GetBytes(""));
Assert.IsTrue(WaitForConfirms(m));
QueueDeclareOk ok2 = m.QueueDeclare(q, false, exclusive, false, null);
Assert.AreEqual(ok2.MessageCount, 1);
}
示例10: AssertExchangeRecovery
protected void AssertExchangeRecovery(IModel m, string x)
{
m.ConfirmSelect();
WithTemporaryNonExclusiveQueue(m, (_, q) =>
{
string rk = "routing-key";
m.QueueBind(q, x, rk);
byte[] mb = RandomMessageBody();
m.BasicPublish(x, rk, null, mb);
Assert.IsTrue(WaitForConfirms(m));
m.ExchangeDeclarePassive(x);
});
}
示例11: WireUpChannelEvents
private void WireUpChannelEvents(IModel channel)
{
if (configuration.PublisherConfirms)
{
channel.ConfirmSelect();
channel.BasicAcks += OnAck;
channel.BasicNacks += OnNack;
}
channel.BasicReturn += OnReturn;
}
示例12: Connect
private void Connect()
{
var cf = new ConnectionFactory();
_connection = cf.CreateConnection();
_channel = _connection.CreateModel();
_channel.ExchangeDeclare(_configurationService.WorkersExchange, ExchangeType.Direct);
_channel.QueueDeclare(_configurationService.WorkerStatusQueue, false, false, true, null);
_channel.QueueBind(_configurationService.WorkerStatusQueue, _configurationService.WorkersExchange, string.Empty);
_channel.QueueDeclare(_configurationService.WorkerPingQueue, false, false, true, null);
_channel.QueueBind(_configurationService.WorkerPingQueue, _configurationService.WorkersExchange, string.Empty);
_channel.ConfirmSelect();
}
示例13: InitializeModel
protected override void InitializeModel(IModel model)
{
model.BasicQos(0, 1, false);
model.ConfirmSelect();
var args = new Dictionary<string, object>();
if (_setup.Options.IncludeProcessCommandLineInQueueArguments)
{
args.Add(ReaderQueueArguments.CommandLine, Environment.CommandLine);
}
args.Add(ReaderQueueArguments.ProcessStartTime, ((DateTimeOffset)_proc.StartTime).ToString());
args.Add(ReaderQueueArguments.ProcessId, _proc.Id);
args.Add(ReaderQueueArguments.MachineName, Environment.MachineName);
args.Add(ReaderQueueArguments.CreationTime, DateTimeOffset.Now.ToString());
args.Add(ReaderQueueArguments.UserName, Environment.UserName);
args.Add(ReaderQueueArguments.UserDomainName, Environment.UserDomainName);
args.Add(ReaderQueueArguments.AppDomainFriendlyName, AppDomain.CurrentDomain.FriendlyName);
args.Add(ReaderQueueArguments.AppDomainFriendlId, AppDomain.CurrentDomain.Id);
#if DEBUG
args.Add(ReaderQueueArguments.Stacktrace, Environment.StackTrace);
#endif
var autoDeleteQueue = !_setup.IsDurable;
var queueTtl = _setup.QueueTimeToLive;
if (autoDeleteQueue && !queueTtl.HasValue)
{
queueTtl = TimeSpan.FromMinutes(20);
}
var appIdentity = AppDomain.CurrentDomain.ApplicationIdentity;
args.Add(ReaderQueueArguments.ApplicationIdentity, (appIdentity == null) ? string.Empty : appIdentity.ToString());
if (queueTtl.HasValue)
{
args.Add("x-expires", (int)queueTtl.Value.TotalMilliseconds);
}
if (_setup.MaxPriority.HasValue)
{
args.Add("x-max-priority", _setup.MaxPriority.Value);
}
if (_setup.QueueArguments != null)
{
foreach (var extraOptions in _setup.QueueArguments)
{
args.Add(extraOptions.Key, extraOptions.Value);
}
}
model.QueueDeclare(_setup.QueueName, true, false, autoDeleteQueue, args);
Debug.WriteLine("{0}-{1}: Declared queue [{2}]", DateTime.Now, Thread.CurrentThread.ManagedThreadId, _setup.QueueName);
model.QueueBind(_setup.QueueName, _setup.Exchange, _setup.QueueName);
Debug.WriteLine("{0}-{1}: Bound to queue [{2}]", DateTime.Now, Thread.CurrentThread.ManagedThreadId, _setup.QueueName);
}
示例14: Exchange
/// <summary>
/// Description for Exchange Constructor.</summary>
/// <param name="amqp_host">The ip or hostname of the AMPQ server</param>
/// <param name="config">An ArrayList of Tuples mapping Queues to MessageHandlers.
/// Array list is of the following format:
/// ["<queue_name>", "<message_handler_class>",...]
/// queue_name is arbitrary and can be named according to it's function
/// "message_handler_class" should be the name of a class derived from MessageHandler
/// that handles processing of messages</param>
///<param name="handler_module"> the .NET namespace that contains the MessageHandler
///derivative classes </param>
///<param name="name"> the name of the exchange</param>
public Exchange(string amqp_host, Dictionary<string, List<Dictionary<string, string>>> config, string handler_module, string name, object ui_obj)
{
this.config = config;
this.handler_module = handler_module;
this.name = name;
this.amqp_host = amqp_host;
var factory = new ConnectionFactory() { HostName = amqp_host };
this.connection = factory.CreateConnection();
this.channel = connection.CreateModel();
channel.ConfirmSelect();
channel.ExchangeDeclare(this.name,"direct");
this.delay_channel = connection.CreateModel();
delay_channel.ConfirmSelect();
this.ui_obj = ui_obj;
this.handlers = new ArrayList();
foreach(var outerdict in config)
{
string route = outerdict.Key;
List<Dictionary<string,string>> conf = outerdict.Value;
int redeliver_attempts = Convert.ToInt16(conf[0].Values.First());
int redeliver_delay = Convert.ToInt16(conf[1].Values.First());
bool manual_ack = Convert.ToBoolean(conf[2].Values.First());
Assembly assembly = Assembly.Load(handler_module);
Console.WriteLine(outerdict.Key);
Console.WriteLine(outerdict.Value);
Type classType = assembly.GetType(string.Format("{0}.{1}", handler_module,
outerdict.Key), false, true);
if (classType == null)
{
throw new ImproperlyConfiguredException(
string.Format("class {0} is not defined in {1}",
outerdict.Key, handler_module));
}
string queue_name = Utils.make_queue_name(this.name, route);
string delay_queue_name = Utils.make_queue_name(this.name, route, "delay");
// create a dictionary for storing arguments used in declaring a queue
Dictionary<string, object> queueArgs = new Dictionary<string, object>
{
{"x-ha-policy", "all"},
{"x-ha-sync-mode", "automatic"},
};
this.channel.QueueDeclare(queue_name, true, false, false, queueArgs);
this.channel.QueueBind(queue_name, this.name, route);
// setup arguments for creating MessageHandler instanse
object[] args = new object[] { this.channel, route, outerdict.Value,
this.delay_channel,
string.Format("{0}_delay", route), manual_ack, this.ui_obj};
// create a MessageHandler object
MessageHandler handler = (MessageHandler)Activator.CreateInstance(classType, args);
/*if (outerdict.Value.ContainsKey("redeliver_delay"))
{
delay = Convert.ToInt16(outerdict.Value["redeliver_delay"]);
}
else
{
throw new ImproperlyConfiguredException(
string.Format(
"MessaheHandler for route {0} must define a redelivery_delay",
route));
}*/
Dictionary<string, object> delayQueueArgs = new Dictionary<string, object>
{
{"x-message-ttl", redeliver_delay * 1000},
{"x-dead-letter-exchange", this.name},
{"x-dead-letter-routing-key", queue_name},
{ "x-ha-policy", "all"},
{"x-ha-sync-mode", "automatic"},
};
this.delay_channel.QueueDeclare(delay_queue_name, true, false, false,
delayQueueArgs);
//MessageHandler consumer = new MessageHandler(channel);
this.channel.BasicConsume(queue_name, false, handler);
this.handlers.Add(handler);
}
}
示例15: SpecificRestart
/// <summary>
/// Method that will be called everytime there is a network failure.
/// </summary>
internal override void SpecificRestart(IModel model)
{
Props = model.CreateBasicProperties();
MySettings.ConstructProperties(Props);
if (MySettings.UseConfirms)
{
model.ConfirmSelect();
//requeue all messages that were on the wire. This might lead to duplicates.
if (MySettings.RequeueMessageAfterFailure && _unacked != null)
{
var unacked = new List<Message>(_unacked.Count);
foreach (var m in _unacked.Values)
{
unacked.Add(new Message
{
Failed = m.Failed + 1,
RoutingKey = m.RoutingKey,
Payload = m.Payload
});
}
OnNAckHandler(unacked);
}
_unacked = new ConcurrentDictionary<ulong, Message>();
model.BasicAcks += (_, args) => HandleAcknowledgement(false, args.DeliveryTag, args.Multiple);
model.BasicNacks += (_, args) => HandleAcknowledgement(true, args.DeliveryTag, args.Multiple);
}
}