Queue(队列)-磁盘或RAM上的一种数据结构,用于存储指向消息的链接并提供其副本consumers(给使用者)。Queue这是一个带有状态(可以缓存消息本身)的Erlang进程。一千个队列可以占用大约80Mb。
Binding (绑定)-告诉交换器哪些队列应该接收消息的规则。
目录
临时队列
如果使用参数集创建队列autoDelete,则此队列具有自动删除自身的功能。通常在第一个客户端连接时创建此类队列,并在所有客户端断开连接时将其删除。
exclusive, . , /, . exclusive , autoDelete .
:
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

, 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; }
bool IsDurable { get; }
bool IsExclusive { get; }
bool IsAutoDelete { get; }
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";
public const string Lazy = "lazy";
}
public interface IBinding
{
IExchange Exchange { get; }
string RoutingKey { get; }
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; }
}