当前位置: 首页>>代码示例>>C#>>正文


C# IConsumer.GetQueueDetails方法代码示例

本文整理汇总了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


注:本文中的IConsumer.GetQueueDetails方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。