コード例 #1
0
 /// <summary>
 /// Creates the specified queue on the RabbitMQ server if it does not exist. If binding information has been provided, this will attempt to bind the queue as directed
 /// </summary>
 /// <param name="queueInfo"></param>
 /// <remarks>If you try to create a queue that already exist but you specify different configuration values than what exists,
 /// this will throw</remarks>
 public void CreateQueue(QueueCreationInfo queueInfo)
 {
     using (var channel = PooledConnection.CreateModel())
     {
         RabbitMQHelper.UseConnectionWithRetries(c => c.QueueDeclare(queueInfo.Identifier, queueInfo.Durable, false, false, null), channel);
         if (queueInfo.BindingInfo != null)
         {
             RabbitMQHelper.UseConnectionWithRetries(c => c.QueueBind(queueInfo.Identifier, queueInfo.BindingInfo.ExchangeIdentifier, queueInfo.BindingInfo.RoutingKey), channel);
         }
     }
 }
コード例 #2
0
        private QueueCreationInfo GetQueueCreationInfo(IQueueConfiguration queue)
        {
            try
            {
                var queueInfo = new QueueCreationInfo(queue.QueueIdentifier, true);
                if (!string.IsNullOrEmpty(queue.ExchangeIdentifier))
                {
                    queueInfo.BindingInfo = new ExchangeBindingInfo
                    {
                        ExchangeIdentifier = queue.ExchangeIdentifier,
                        RoutingKey         = queue.RoutingKey ?? string.Empty // Rabbit MQ barfs on null strings
                    };
                }

                return(queueInfo);
            }
            catch (Exception ex)
            {
                OnErrorAction(ex);
                throw;
            }
        }