Exchange- exchanger or exchange point. Messages are sent to it. Exchange Distributes the message into one or more queues. It routes messages to the queue based on the created connections ( bindings) between it and the queue.
Exchangenot an Erlang process . For scalability reasons exchange, this is a string (a link to a module with code where the routing logic lies) in the mnesia built-in database . 1 thousand exchangers will consume only 1MB of memory.
Table of contents
Direct exchange
Direct exchange β , . , . β . .
:

rabbitmq . direct exchange . , .
Topic Exchange
Topic exchange β direct exchange . , , . 0 ( AZ az 0-9), , * #.
:

RabbitMQ 2.4.0 topic exchange 145 . trie implementation, . a.b.c, a.*.b.c, a.#.c b.b.c :

, .
:
- , .. , direct exchangefanout exchange
- , *, ,#.
- topic exchange- direct exchange
Fanout Exchange
Fanout exchange β .
:
:

Headers exchange β (, ) headers . headers Dictionary<, >.
x-match any, (, ). or.
var bindingArguments = new Dictinary<String, Object>();
bindingArguments.add("x-match", "any");
x-match all. , (, ). and.
:

:
- . (, ) headers. , exchange.
Consistent-Hashing Exchange
RabbitMQ.
Consistent-hashing exchange (exchange ) β , , , . ( 0 - n).
β , ( ). .
:

Hash headers . headers, . headers.
, , .
(E2E)
Exchange-to-Exchange ( AMQP. RabbitMQ).
:

E2E , , .
Exchange
RPC . Exchange.Declare, :
exchange RabbitMQ.Client:
channel.ExchangeDeclare(
    exchange: "my_exchange",
    type: "direct",
    durable: "false",
    autoDelete: "false",
    arguments: null
);
- exchangeβ , .
- typeβ
- durableβ- true,- exchange. /.- false,- exchange, /
- autoDeleteβ .- Exchange,
- argumentsβ . ,- alternative exchange( ). , .

exchange , RPC Exchange.DeclareOk. ( Exchange.Declare), Channel.Close OperationInterruptedException, .
. - β RabbitMQ .
Exchange
RabbitMQ guest (username: guest password: guest). , guest . Exchanges Add a new exchange. :

. , Internal, E2E. Producer .
. , .. (). . .
, , fanout exchange, 1:1 . , fanout exchange .
, topic exchange , , direct exchnge, .. topic exchange.
exchange , , .
exchange .
Queues Bindings.
Code
C#, . .
public interface IExchange
{
    
    
    
    
    string Name { get; }
    
    
    
    string Type { get; }
    
    
    
    
    
    
    
    
    
    bool IsDurable { get; }
    
    
    
    
    bool IsAutoDelete { get; }
    
    
    
    IDictionary<string, object> Arguments { get; }
}
public static class ExchangeType
{
    public const string Direct = "direct";
    public const string Topic = "topic";
    public const string Fanout = "fanout";
    public const string Header = "headers";
}
public class Exchange : IExchange
{
    public Exchange(
           string name, 
           string type = ExchangeType.Direct, 
           bool durable = true, 
           bool autoDelete = false, 
           IDictionary<string, object> arguments = null)
    {
        Name = name ??
            throw new ArgumentNullException(name, $"{name} must not be null");
        Type = type;
        IsDurable = durable;
        IsAutoDelete = autoDelete;
        Arguments = arguments ?? new Dictionary<string, object>();
    }
    public string Name { get; }
    public string Type { get; }
    public bool IsDurable { get; }
    public bool IsAutoDelete { get; }
    public IDictionary<string, object> Arguments { get; }
    
    
    
    
    
    
    
    public static IExchange GetDefault()
    {
        return new Exchange("");
    }
}