Exchange
- Wärmetauscher oder Wechselstelle. Nachrichten werden an ihn gesendet. Exchange
Verteilt die Nachricht in eine oder mehrere Warteschlangen. Es leitet Nachrichten basierend auf den erstellten Verbindungen ( bindings
) zwischen ihr und der Warteschlange an die Warteschlange weiter.
Exchange
kein Erlang-Prozess . Aus Gründen der Skalierbarkeit exchange
ist dies eine Zeichenfolge (eine Verknüpfung zu einem Modul mit Code, in dem die Routing-Logik liegt) in der in mnesia integrierten Datenbank . Tausend Austauscher verbrauchen nur 1 MB Speicher.
Inhaltsverzeichnis
Direkter Austausch
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("");
}
}