-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathexchange_impl.dart
94 lines (80 loc) · 2.94 KB
/
exchange_impl.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
part of dart_amqp.client;
class _ExchangeImpl implements Exchange {
final String _name;
@override
final ExchangeType type;
@override
final _ChannelImpl channel;
_ExchangeImpl(this.channel, this._name, this.type);
@override
String get name => _name;
@override
Future<Exchange> delete({bool ifUnused = false, bool noWait = false}) {
ExchangeDelete deleteRequest = ExchangeDelete()
..reserved_1 = 0
..exchange = name
..ifUnused = ifUnused
..noWait = noWait;
Completer<Exchange> completer = Completer<Exchange>();
channel.writeMessage(deleteRequest,
completer: completer, futurePayload: this, noWait: noWait);
return completer.future;
}
@override
void publish(Object message, String? routingKey,
{MessageProperties? properties,
bool mandatory = false,
bool immediate = false}) {
if (!type.isCustom &&
type != ExchangeType.FANOUT &&
type != ExchangeType.HEADERS &&
(routingKey == null || routingKey.isEmpty)) {
throw ArgumentError("A valid routing key needs to be specified");
}
BasicPublish pubRequest = BasicPublish()
..reserved_1 = 0
..routingKey = routingKey
..exchange = name
..mandatory = mandatory
..immediate = immediate;
channel.writeMessage(pubRequest,
properties: properties, payloadContent: message);
}
@override
Future<Consumer> bindPrivateQueueConsumer(List<String>? routingKeys,
{String? consumerTag, bool noAck = true}) async {
// Fanout and headers exchanges do not need to specify any keys. Use the default one if none is specified
if ((type == ExchangeType.FANOUT || type == ExchangeType.HEADERS) &&
(routingKeys == null || routingKeys.isEmpty)) {
routingKeys = [""];
}
if ((routingKeys == null || routingKeys.isEmpty)) {
throw ArgumentError(
"One or more routing keys needs to be specified for this exchange type");
}
Queue queue = await channel.privateQueue();
for (String routingKey in routingKeys) {
await queue.bind(this, routingKey);
}
return queue.consume(consumerTag: consumerTag, noAck: noAck);
}
@override
Future<Consumer> bindQueueConsumer(
String queueName, List<String>? routingKeys,
{String? consumerTag, bool noAck = true}) async {
// Fanout and headers exchanges do not need to specify any keys. Use the default one if none is specified
if ((type == ExchangeType.FANOUT || type == ExchangeType.HEADERS) &&
(routingKeys == null || routingKeys.isEmpty)) {
routingKeys = [""];
}
if ((routingKeys == null || routingKeys.isEmpty)) {
throw ArgumentError(
"One or more routing keys needs to be specified for this exchange type");
}
Queue queue = await channel.queue(queueName);
for (String routingKey in routingKeys) {
await queue.bind(this, routingKey);
}
return queue.consume(consumerTag: consumerTag, noAck: noAck);
}
}