本文整理汇总了C#中QueueName.GetRetryQueueName方法的典型用法代码示例。如果您正苦于以下问题:C# QueueName.GetRetryQueueName方法的具体用法?C# QueueName.GetRetryQueueName怎么用?C# QueueName.GetRetryQueueName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueueName
的用法示例。
在下文中一共展示了QueueName.GetRetryQueueName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RabbitMQQueue
public RabbitMQQueue(QueueName queueName, IQueueListener listener, IConnection connection,
Encoding encoding = null, QueueOptions options = default(QueueOptions))
{
if (queueName == null) throw new ArgumentNullException("queueName");
if (listener == null) throw new ArgumentNullException("listener");
if (connection == null) throw new ArgumentNullException("connection");
_queueName = queueName;
_queueExchange = _queueName.GetExchangeName();
_retryQueueName = queueName.GetRetryQueueName();
_retryExchange = _queueName.GetRetryExchangeName();
_deadLetterExchange = _queueName.GetDeadLetterExchangeName();
_listener = listener;
_connection = connection;
_encoding = encoding ?? Encoding.UTF8;
_ttl = options.TTL;
_maxAttempts = Math.Max(options.MaxAttempts, 1);
_retryDelay = options.RetryDelay < TimeSpan.Zero ? TimeSpan.Zero : options.RetryDelay;
_cancellationTokenSource = new CancellationTokenSource();
var autoAcknowledge = options.AutoAcknowledge;
var concurrencyLimit = Math.Max(options.ConcurrencyLimit, 1);
_consumers = new DurableConsumer[concurrencyLimit];
for (var i = 0; i < _consumers.Length; i++)
{
var consumerTag = _queueName + "_" + i;
_consumers[i] = new DurableConsumer(_connection, queueName, HandleDelivery, consumerTag,
autoAcknowledge);
}
}
示例2: Given_Existing_Queue_When_New_Message_Queued_Then_Listener_Should_Fire
public async Task Given_Existing_Queue_When_New_Message_Queued_Then_Listener_Should_Fire()
{
var listenerCalledEvent = new ManualResetEvent(false);
var queueName = new QueueName(Guid.NewGuid().ToString());
var rmqQueueingService = new RabbitMQMessageQueueingService(RabbitMQUri);
try
{
var mockListener = new Mock<IQueueListener>();
mockListener.Setup(
x =>
x.MessageReceived(It.IsAny<Message>(), It.IsAny<IQueuedMessageContext>(),
It.IsAny<CancellationToken>()))
.Callback<Message, IQueuedMessageContext, CancellationToken>((msg, ctx, ct) =>
{
ctx.Acknowledge();
listenerCalledEvent.Set();
})
.Returns(Task.FromResult(true));
await rmqQueueingService.CreateQueue(queueName, mockListener.Object, new QueueOptions {MaxAttempts = 1});
var message = new Message(new MessageHeaders
{
{HeaderName.ContentType, "text/plain"},
{HeaderName.MessageId, Guid.NewGuid().ToString()}
}, "Hello, world!");
await rmqQueueingService.EnqueueMessage(queueName, message, Thread.CurrentPrincipal);
await listenerCalledEvent.WaitOneAsync(TimeSpan.FromSeconds(1));
var messageEqualityComparer = new MessageEqualityComparer();
mockListener.Verify(
x =>
x.MessageReceived(It.Is<Message>(m => messageEqualityComparer.Equals(m, message)),
It.IsAny<IQueuedMessageContext>(), It.IsAny<CancellationToken>()), Times.Once());
Assert.That(GetQueueDepth(queueName), Is.EqualTo(0));
Assert.That(GetQueueDepth(queueName.GetRetryQueueName()), Is.EqualTo(0));
}
finally
{
rmqQueueingService.Dispose();
DeleteQueue(queueName);
}
}
示例3: Given_10_Existing_Messages_10_New_Messages_Then_Listener_Should_Fire_For_All_20_Messages
public async Task Given_10_Existing_Messages_10_New_Messages_Then_Listener_Should_Fire_For_All_20_Messages()
{
var queueName = new QueueName(Guid.NewGuid().ToString());
var rmqQueueingService = new RabbitMQMessageQueueingService(RabbitMQUri);
try
{
var existingMessages = Enumerable.Range(1, 10)
.Select(i => new Message(new MessageHeaders
{
{HeaderName.ContentType, "text/plain"},
{HeaderName.MessageId, Guid.NewGuid().ToString()}
}, "Hello, world! (" + i + ")"))
.ToList();
await Task.WhenAll(existingMessages.Select(msg => StageExistingMessage(msg, queueName)));
var newMessages = Enumerable.Range(11, 10)
.Select(i => new Message(new MessageHeaders
{
{HeaderName.ContentType, "text/plain"},
{HeaderName.MessageId, Guid.NewGuid().ToString()}
}, "Hello, world! (" + i + ")"))
.ToList();
var listenerCountdown = new CountdownEvent(existingMessages.Count + newMessages.Count);
var mockListener = new Mock<IQueueListener>();
mockListener.Setup(
x =>
x.MessageReceived(It.IsAny<Message>(), It.IsAny<IQueuedMessageContext>(),
It.IsAny<CancellationToken>()))
.Callback<Message, IQueuedMessageContext, CancellationToken>((msg, ctx, ct) =>
{
ctx.Acknowledge();
listenerCountdown.Signal();
})
.Returns(Task.FromResult(true));
await rmqQueueingService.CreateQueue(queueName, mockListener.Object, new QueueOptions {MaxAttempts = 1});
await Task.WhenAll(newMessages.Select(msg =>
rmqQueueingService.EnqueueMessage(queueName, msg, Thread.CurrentPrincipal)));
var timedOut = !await listenerCountdown.WaitHandle.WaitOneAsync(TimeSpan.FromSeconds(10));
Assert.That(timedOut, Is.False, "Timed out waiting for listeners to be called");
var messageEqualityComparer = new MessageEqualityComparer();
var allmessages = existingMessages.Union(newMessages);
foreach (var message in allmessages)
{
mockListener.Verify(
x =>
x.MessageReceived(It.Is<Message>(m => messageEqualityComparer.Equals(m, message)),
It.IsAny<IQueuedMessageContext>(), It.IsAny<CancellationToken>()), Times.Once());
}
Assert.That(GetQueueDepth(queueName), Is.EqualTo(0));
Assert.That(GetQueueDepth(queueName.GetRetryQueueName()), Is.EqualTo(0));
}
finally
{
rmqQueueingService.Dispose();
DeleteQueue(queueName);
}
}
示例4: DeleteQueue
private static void DeleteQueue(QueueName queueName)
{
var connectionFactory = new ConnectionFactory { Uri = RabbitMQUri.ToString() };
using (var connection = connectionFactory.CreateConnection())
using (var channel = connection.CreateModel())
{
// We have to declare the queue as a persistence queue because this is
// called before the queue is created by the RabbitMQQueueingService
var queueExchange = queueName.GetExchangeName();
var retryExchange = queueName.GetRetryExchangeName();
var deadLetterExchange = queueName.GetDeadLetterExchangeName();
var retryQueueName = queueName.GetRetryQueueName();
channel.QueueDeleteNoWait(queueName, false, false);
channel.QueueDeleteNoWait(retryQueueName, false, false);
channel.ExchangeDeleteNoWait(queueExchange, false);
channel.ExchangeDeleteNoWait(retryExchange, false);
channel.ExchangeDeleteNoWait(deadLetterExchange, false);
}
}
示例5: Given_Auto_Acknowledge_Queue_When_Not_Acknowledged_Then_Message_Should_Be_Deleted
public async Task Given_Auto_Acknowledge_Queue_When_Not_Acknowledged_Then_Message_Should_Be_Deleted()
{
var queueName = new QueueName(Guid.NewGuid().ToString());
var rmqQueueingService = new RabbitMQMessageQueueingService(RabbitMQUri);
try
{
var listenerCalledEvent = new ManualResetEvent(false);
var mockListener = new Mock<IQueueListener>();
mockListener.Setup(x =>
x.MessageReceived(It.IsAny<Message>(), It.IsAny<IQueuedMessageContext>(),
It.IsAny<CancellationToken>()))
.Callback<Message, IQueuedMessageContext, CancellationToken>(
(msg, ctx, ct) => { listenerCalledEvent.Set(); })
.Returns(Task.FromResult(true));
await rmqQueueingService.CreateQueue(queueName, mockListener.Object, new QueueOptions {AutoAcknowledge = true});
var message = new Message(new MessageHeaders
{
{HeaderName.ContentType, "text/plain"},
{HeaderName.MessageId, Guid.NewGuid().ToString()}
}, "Hello, world!");
await rmqQueueingService.EnqueueMessage(queueName, message, Thread.CurrentPrincipal);
await listenerCalledEvent.WaitOneAsync(TimeSpan.FromSeconds(1));
// The listener is called before the file is deleted, so there is a possible
// race condition here. Wait for a second to allow the delete to take place
// before enumerating the files to see that they were actually deleted.
await Task.Delay(TimeSpan.FromSeconds(1));
var messageEqualityComparer = new MessageEqualityComparer();
mockListener.Verify(x =>
x.MessageReceived(It.Is<Message>(m => messageEqualityComparer.Equals(m, message)),
It.IsAny<IQueuedMessageContext>(), It.IsAny<CancellationToken>()), Times.Once());
Assert.That(GetQueueDepth(queueName), Is.EqualTo(0));
Assert.That(GetQueueDepth(queueName.GetRetryQueueName()), Is.EqualTo(0));
}
finally
{
rmqQueueingService.Dispose();
DeleteQueue(queueName);
}
}