أرنب MQ. الجزء 3. فهم قوائم الانتظار والارتباطات

Queue(قائمة الانتظار) - بنية بيانات على القرص أو في ذاكرة الوصول العشوائي (RAM) تقوم بتخزين روابط للرسائل وتعطي نسخها consumers(للمستهلكين). Queueإنها عملية إرلانج مع حالة (حيث يمكن تخزين الرسائل نفسها مؤقتًا). يمكن لألف طابور أن تشغل حوالي 80 ميجا بايت.


Binding (ملزم) - قاعدة تخبر المبادل بأي قوائم الانتظار يجب أن يتلقى الرسائل.


جدول المحتويات



قوائم الانتظار المؤقتة


إذا تم إنشاء قائمة الانتظار باستخدام مجموعة المعلمات autoDelete، فإن قائمة الانتظار هذه تكتسب القدرة على حذف نفسها تلقائيًا . عادةً ما يتم إنشاء قوائم الانتظار هذه عندما يتصل العميل الأول ويتم حذفها عند قطع اتصال كافة العملاء.


exclusive, . , /, . exclusive , autoDelete .


:


  • ,
  • binding churn. , / . .


durable, /. Queue.Delete.


Highly Available


HA RabbitMQ. , , .


- HA , , HA . - , .


HA .


أرنب


:


  • HA . HA HA RabbitMQ (2-3 )


RPC . Queue.Declare, :



RabbitMQ.Client:


// ...
channel.QueueDeclare(
    queue: "my_queue",
    durable: false,
    exclusive: false,
    autoDelete: false,
    arguments: null
);
// ...

  • queue — , .
  • durable — true, /
  • exclusive — true,
  • autoDelete — true,
  • arguments — . .

arguments

  • x-message-ttl(x-message-time-to-live) — . x-message-ttl, , . x-message-ttl . . . x-message-ttl, .
  • x-expires — . . , , Basic.Cancel . , Basic.Get. , . , .
  • x-max-length — . ,

أرنب


  • x-max-lenght-bytes — . ( )
  • x-overflow — . : drop-head ( ) reject-publish. drop-head, . reject-publish,
  • x-dead-letter-exchange — exchange, ,
  • x-dead-letter-routing-key
  • x-max-priority — 255 (RabbitMQ 3.5.0 ). , . ,
  • x-queue-mode. . . , , ,
  • x-queue-master-locator — ,
  • x-ha-policy — HA . all, . nodes,
  • x-ha-nodes — , HA

أرنب mq_10


, RPC Queue.DeclareOk. ( Queue.Declare), Channel.Close OperationInterruptedException, .


Queue.Declare . , , , .


Queue.Declare , Channel.Close OperationInterruptedException, 403 .


, >= 10 , , GC , , .


Queue


RabbitMQ guest (username: guest password: guest). , guest . Queues Add a new queue. :


أرنب


Add queues, .


أرنب


. , consumers, / , .


Binding


RPC . Queue.Bind, :



RabbitMQ.Client:


//...
channel.QueueBind(
    queue: queueName,
    exchange: "my_exchange",
    routingKey: "my_key",
    arguments: null
);
//...

  • queue
  • exchange
  • routingKey
  • arguments

أرنب


, RPC Queue.BindOk.


Binding


RabbitMQ guest (username: guest password: guest). , guest . Queues my_queue. bindings:


أرنب


Bind, :


أرنب


Code


في هذا القسم ، سنصف قائمة الانتظار والملزمة باستخدام كود C # ، لذلك إذا احتجنا إلى تطوير مكتبة. ربما سيكون مفيدا للإدراك.


public interface IQueue
    {        
        string Name { get; }

        /// <summary>
        ///       true,  queue   . 
        ///            
        ///       /. 
        ///       false,  queue     , 
        ///      /  
        /// </summary>
        bool IsDurable { get; }

        /// <summary>
        ///        true,  
        ///          
        ///       consumer-
        /// </summary>
        bool IsExclusive { get; }

        /// <summary>
        ///      . 
        ///       ,    .
        /// </summary>
        bool IsAutoDelete { get; }

        /// <summary>
        ///      
        /// </summary>
        IDictionary<string, object> Arguments { get; }
    }

public class Queue : IQueue
    {
        public Queue(
             string name, 
             bool isDurable = true, 
             bool isExclusive = false, 
             bool isAutoDelete = false, 
             IDictionary<string, object> arguments = null)
        {
            Name = name ??
                throw new ArgumentNullException(name, $"{name} must not be null");

            IsDurable = isDurable;
            IsExclusive = isExclusive;
            IsAutoDelete = isAutoDelete;
            Arguments = arguments ?? new Dictionary<string, object>();
        }

        public string Name { get; }
        public bool IsDurable { get; }
        public bool IsExclusive { get; }
        public bool IsAutoDelete { get; }
        public IDictionary<string, object> Arguments { get; }
    }

public static class QueueMode
    {       
        public const string Default = "default";
        /// <summary>
        ///      .     
        ///          ,   
        ///       
        /// </summary>
        public const string Lazy = "lazy";
    }

public interface IBinding
    {
        /// <summary>
        ///     ,    
        /// </summary>
        IExchange Exchange { get; }

        /// <summary>
        ///      
        /// </summary>
        string RoutingKey { get; }

        /// <summary>
        ///      
        /// </summary>
        IDictionary<string, object> Arguments { get; }
    }

public class Binding : IBinding
    {
        public Binding(
             IExchange exchange, 
             string routingKey, 
             IDictionary<string, object> arguments)
        {
            Exchange = exchange;
            RoutingKey = routingKey;
            Arguments = arguments;
        }

        public IExchange Exchange { get; }
        public string RoutingKey { get; }
        public IDictionary<string, object> Arguments { get; }
    }

All Articles