本文整理汇总了C#中QueueName类的典型用法代码示例。如果您正苦于以下问题:C# QueueName类的具体用法?C# QueueName怎么用?C# QueueName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueueName类属于命名空间,在下文中一共展示了QueueName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitDb
private static IDbConnectionProvider InitDb(DirectoryInfo directory, QueueName queueName)
{
var dbPath = Path.Combine(directory.FullName, queueName + ".db");
var connectionStringSettings = new ConnectionStringSettings
{
Name = dbPath,
ConnectionString = "Data Source=" + dbPath + "; Version=3",
ProviderName = "System.Data.SQLite"
};
var connectionProvider = new SingletonConnectionProvider(connectionStringSettings);
var connection = connectionProvider.GetConnection();
try
{
using (var command = connection.CreateCommand())
{
command.CommandType = CommandType.Text;
command.CommandText = new SQLiteDialect().CreateMessageQueueingServiceObjectsCommand;
command.ExecuteNonQuery();
}
}
finally
{
connectionProvider.ReleaseConnection(connection);
}
return connectionProvider;
}
示例2: NextAsync
public Task<PollerResult<Event>> NextAsync(QueueName name)
{
var connection = _connectionProvider.GetConnection();
var result = new PollerResult<Event>(false , Event.Empty);
using (var channel = connection.CreateModel())
{
var consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(name.SubscriptionName, true, consumer);
BasicDeliverEventArgs eventArgs = null;
if (consumer.Queue.Dequeue((int)_longPollingTimeout.TotalMilliseconds,
out eventArgs))
{
var @event = new Event()
{
Body = Encoding.UTF8.GetString(eventArgs.Body),
QueueName = name.SubscriptionName,
UnderlyingMessage = eventArgs,
ContentType = "text/plain", // should it be JSON?
EventType = name.SubscriptionName
};
result = new PollerResult<Event>(true, @event);
}
return Task.FromResult(result);
}
}
示例3: PushBatchAsync
public async Task PushBatchAsync(IEnumerable<Event> messages)
{
const int BatchSize = 50;
var msgs = messages.ToArray();
if (!msgs.Any())
return;
var message = msgs.First();
var queueName = new QueueName(message.QueueName);
int i = 0;
if (queueName.IsSimpleQueue)
{
var client = _clientProvider.GetQueueClient(queueName);
while (i < msgs.Length)
{
await client.SendBatchAsync(msgs.Skip(i).Take(BatchSize).Select(x => x.ToMessage()));
i += BatchSize;
}
}
else
{
var client = _clientProvider.GetTopicClient(queueName);
while (i < msgs.Length)
{
await client.SendBatchAsync(msgs.Skip(i).Take(BatchSize).Select(x => x.ToMessage()));
i += BatchSize;
}
}
}
示例4: RouteRegistration
public RouteRegistration(string messageFilter, QueueName destination)
{
Condition.Requires(messageFilter, "messageFilter").IsNotNullOrEmpty();
Condition.Requires(destination, "destination").IsNotNull();
MessageFilter = messageFilter;
Destination = destination;
}
示例5: SubscribeCommand
public SubscribeCommand(Type subscribedMessageType, QueueName subscriberQueue)
{
Condition.Requires(subscribedMessageType, "subscribedMessageType").IsNotNull();
Condition.Requires(subscriberQueue, "subscriberQueue").IsNotNull();
SubscribedMessagesTypeName = subscribedMessageType.AssemblyQualifiedName;
SubscriberQueueName = subscriberQueue.Name;
}
示例6: MsmqQueueObserver
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Object"/> class.
/// </summary>
public MsmqQueueObserver(string serviceBusName, QueueName inputQueue, QueueName errorQueue, MsmqQueueTransport queueTransport)
{
_serviceBusName = serviceBusName;
_inputQueue = inputQueue;
_errorQueue = errorQueue;
_queueTransport = queueTransport;
}
示例7: SQLMessageQueue
public SQLMessageQueue(IDbConnectionProvider connectionProvider, ISQLDialect dialect, QueueName queueName,
IQueueListener listener, QueueOptions options = default(QueueOptions))
{
if (connectionProvider == null) throw new ArgumentNullException("connectionProvider");
if (dialect == null) throw new ArgumentNullException("dialect");
if (queueName == null) throw new ArgumentNullException("queueName");
if (listener == null) throw new ArgumentNullException("listener");
_connectionProvider = connectionProvider;
_dialect = dialect;
_queueName = queueName;
_listener = listener;
_autoAcknowledge = options.AutoAcknowledge;
_maxAttempts = options.MaxAttempts <= 0 ? 10 : options.MaxAttempts;
_retryDelay = options.RetryDelay < TimeSpan.Zero ? TimeSpan.Zero : options.RetryDelay;
var concurrencyLimit = options.ConcurrencyLimit <= 0
? QueueOptions.DefaultConcurrencyLimit
: options.ConcurrencyLimit;
_concurrentMessageProcessingSlot = new SemaphoreSlim(concurrencyLimit);
_cancellationTokenSource = new CancellationTokenSource();
_queuedMessages = new BufferBlock<SQLQueuedMessage>(new DataflowBlockOptions
{
CancellationToken = _cancellationTokenSource.Token
});
}
示例8: Prepare
/// <summary>
/// Stages indexes. Should run only using one process.
/// </summary>
/// <param name="scope"></param>
/// <param name="documentType"></param>
/// <param name="rebuild"></param>
/// <exception cref="System.ArgumentNullException">scope</exception>
public void Prepare(string scope, string documentType = "", bool rebuild = false)
{
if (String.IsNullOrEmpty(scope))
throw new ArgumentNullException("scope");
foreach (var builder in _indexBuilders)
{
// skip not requested indexers or index using all if index is not specified
if (!String.IsNullOrEmpty(documentType) && !documentType.Equals(builder.DocumentType))
continue;
// Execute builder, which will create partitions and put them in the queue
var queueName = new QueueName("index-{0}-{1}-in", scope, builder.DocumentType);
var config = GetBuildConfig(_repository, queueName.Scope, queueName.DocumentType);
var lastBuild = DateTime.UtcNow;
var newBuildDate = lastBuild;
if (config.Status == BuildStatus.NeverStarted.GetHashCode() || rebuild) // build was never started, so set min date
{
rebuild = true;
lastBuild = DateTime.MinValue;
config.LastBuildDate = DateTime.UtcNow.AddYears(-30); // have to set the date to something repository won't complain
}
else
{
lastBuild = config.LastBuildDate.AddSeconds(-30); // make sure we get all the changes
}
// Delete all the records
if (rebuild)
{
_searchProvider.RemoveAll(queueName.Scope, queueName.DocumentType);
}
var partitions = builder.CreatePartitions(queueName.Scope, lastBuild);
var newPartitionsExist = false; // tells if there are any partitions that has been processed
foreach (var partition in partitions)
{
newPartitionsExist = true;
//_observer.Notify(new ConsumeBegin(msg, consumer, envelope.QueueName));
_messageSender.Send(queueName.ToString(), partition);
}
var newBuildStatus = BuildStatus.Started;
if (newPartitionsExist)
{
_messageSender.Send(queueName.ToString(), new SearchIndexStatusMessage(queueName.Scope, queueName.DocumentType, BuildStatus.Completed));
}
else
{
newBuildStatus = BuildStatus.Completed;
}
config.LastBuildDate = newBuildDate;
config.Status = newBuildStatus.GetHashCode();
_repository.UnitOfWork.Commit();
}
}
示例9: 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);
}
}
示例10: Given_ClaimsPrincipal_When_Reading_Principal_Should_Be_Read
public async Task Given_ClaimsPrincipal_When_Reading_Principal_Should_Be_Read()
{
var tempDir = GetTempDirectory();
var queueName = new QueueName(Guid.NewGuid().ToString());
var queuePath = Path.Combine(tempDir.FullName, queueName);
var queueDir = new DirectoryInfo(queuePath);
if (!queueDir.Exists)
{
queueDir.Create();
}
var message = new Message(new MessageHeaders
{
{HeaderName.ContentType, "text/plain"},
{HeaderName.MessageId, Guid.NewGuid().ToString()}
}, "Hello, world!");
var senderPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new[]
{
new Claim("username", "testuser"),
new Claim("role", "testrole")
}));
var file = (await MessageFile.Create(queueDir, message, senderPrincipal)).File;
var messageFile = new MessageFile(file);
var readSenderPrincipal = await messageFile.ReadSenderPrincipal();
var readMessage = await messageFile.ReadMessage();
Assert.That(readSenderPrincipal, Is.EqualTo(senderPrincipal).Using(new ClaimsPrincipalEqualityComparer()));
Assert.That(readMessage, Is.EqualTo(message).Using(new MessageEqualityComparer()));
}
示例11: DeleteQueueAsyncAwait
public async Task DeleteQueueAsyncAwait()
{
#region DeleteQueueAsync (await)
IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider);
QueueName queueName = new QueueName("ExampleQueue");
await queueingService.DeleteQueueAsync(queueName, CancellationToken.None);
#endregion
}
示例12: CreateQueue
public void CreateQueue()
{
#region CreateQueueAsync (TPL)
IQueueingService queueingService = new CloudQueuesProvider(identity, region, clientId, internalUrl, identityProvider);
QueueName queueName = new QueueName("ExampleQueue");
Task<bool> task = queueingService.CreateQueueAsync(queueName, CancellationToken.None);
#endregion
}
示例13: PublishMessage
public static async Task PublishMessage(Message message, IPrincipal principal, IConnection connection,
QueueName queueName, string exchange = "", Encoding encoding = null, int attempts = 0)
{
using (var channel = connection.CreateModel())
{
await PublishMessage(message, principal, channel, queueName, exchange, encoding, attempts);
}
}
示例14: CreateQueue
public Task CreateQueue(QueueName queueName, IQueueListener listener, QueueOptions options = default(QueueOptions), CancellationToken cancellationToken = default(CancellationToken))
{
if (!_queues.TryAdd(queueName, new InMemoryQueue(listener, options)))
{
throw new QueueAlreadyExistsException(queueName);
}
return Task.FromResult(true);
}
示例15: HandlingRule
/// <summary>
/// Initializes a new <see cref="HandlingRule"/> with the supplied message
/// <paramref name="specification"/>, <see cref="MessageHandler"/>, and
/// <paramref name="queueName"/>.
/// </summary>
/// <param name="specification">The message specification that selects messages
/// to which the handling rule applies</param>
/// <param name="messageHandler">The handler to which messages matching the
/// specification will be routed</param>
/// <param name="queueName">(Optional) The name of the queue in which matching
/// messages will be placed while they await handling</param>
/// <remarks>
/// If the <paramref name="queueName"/> is ommitted, a default queue name will
/// be generated based on the MD5 hash of the full type name of the supplied
/// <paramref name="messageHandler"/>
/// </remarks>
/// <seealso cref="GenerateQueueName"/>
public HandlingRule(IMessageSpecification specification, IMessageHandler messageHandler,
QueueName queueName = null)
{
if (specification == null) throw new ArgumentNullException("specification");
if (messageHandler == null) throw new ArgumentNullException("messageHandler");
_specification = specification;
_messageHandler = messageHandler;
_queueName = queueName ?? GenerateQueueName(messageHandler);
}