Exchange
- échangeur ou point d'échange. Des messages lui sont envoyés. Exchange
Distribue le message dans une ou plusieurs files d'attente. Il achemine les messages vers la file d'attente en fonction des connexions créées ( bindings
) entre celui-ci et la file d'attente.
Exchange
pas un processus Erlang . Pour des raisons d'évolutivité exchange
, il s'agit d'une chaîne (un lien vers un module avec le code où se trouve la logique de routage) dans la base de données intégrée mnesia . 1 000 échangeurs ne consommeront que 1 Mo de mémoire.
Table des matières
Échange direct
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 exchange
fanout 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("");
}
}