本文整理汇总了C#中IConsumer.GetQueueDetails方法的典型用法代码示例。如果您正苦于以下问题:C# IConsumer.GetQueueDetails方法的具体用法?C# IConsumer.GetQueueDetails怎么用?C# IConsumer.GetQueueDetails使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConsumer
的用法示例。
在下文中一共展示了IConsumer.GetQueueDetails方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddConsumerToQueue
protected virtual void AddConsumerToQueue(IConsumer consumer)
{
var queue = consumer.GetQueueDetails();
if (queue == null || string.IsNullOrEmpty(queue.Name))
throw new Exception("Invalid queue details");
if(!CanPerformChannelOperations)
throw new InvalidOperationException("Cannot accept new consumers at the moment");
var model = _streamConnection.CreateModel();
StreamSubscriber subscriber = null;
try
{
subscriber = new StreamSubscriber(model, consumer, Dispatcher);
subscriber.StartConsuming(queue.Name);
}
catch
{
if (subscriber != null)
subscriber.Dispose();
throw;
}
}
开发者ID:sportingsolutions,项目名称:SS.Integration.UnifiedDataAPIClient.DotNet,代码行数:27,代码来源:StreamController.cs
示例2: Connect
private void Connect(IConsumer consumer)
{
if (State != ConnectionState.CONNECTED)
{
// this prevents any other execution of EstablishConnection().
// EstablishConnection() wakes up any sleeping threads when it finishes
lock (_connectionLock)
{
while (State == ConnectionState.CONNECTING)
{
// wait until the connection is established
Monitor.Wait(_connectionLock);
}
if (State == ConnectionState.CONNECTED || _cancellationTokenSource.IsCancellationRequested)
return;
State = ConnectionState.CONNECTING;
}
// GetQueueDetails() returns the credentials for connecting to the AMQP server
// but it also asks the server to create an AMQP queue for the caller.
// As the time to establish a connection could take a while (just think about
// a not reliable network), the created AMQP queue could expire before we
// call BasicConsume() on it.
//
// To prevent this situation, we call GetQueueDetails() twice for the consumer
// who establish the connection, one here, and the second time on
// AddConsumeToQueue()
QueueDetails queue = null;
try
{
queue = consumer.GetQueueDetails();
if (queue == null || string.IsNullOrEmpty(queue.Name))
{
throw new Exception("queue's name is not valid for consumerId=" + consumer.Id);
}
}
catch (Exception e)
{
_logger.Error("Error acquiring queue details for consumerId=" + consumer.Id, e);
OnConnectionStatusChanged(ConnectionState.DISCONNECTED);
throw;
}
var factory = new ConnectionFactory {
RequestedHeartbeat = UDAPI.Configuration.AMQPMissedHeartbeat,
HostName = queue.Host,
Port = queue.Port,
UserName = queue.UserName,
Password = queue.Password,
VirtualHost = "/" + queue.VirtualHost // this is not used anymore, we keep it for retro-compatibility
};
EstablishConnection(factory);
}
}
开发者ID:sportingsolutions,项目名称:SS.Integration.UnifiedDataAPIClient.DotNet,代码行数:63,代码来源:StreamController.cs