forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
receive_logs_topic.dart
40 lines (35 loc) · 1.17 KB
/
receive_logs_topic.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
import "dart:io";
import "package:dart_amqp/dart_amqp.dart";
void main (List<String> arguments) {
if (arguments.isEmpty) {
print("Usage: receive_logs_direct.dart <topic> [<topic>, ...]");
return;
}
ConnectionSettings settings = new ConnectionSettings(
host: "localhost"
);
Client client = new Client(settings: settings);
ProcessSignal.sigint.watch().listen((_) {
client.close().then((_) {
print("close client");
exit(0);
});
});
List<String> routingKeys = arguments.sublist(0);
client
.channel()
.then((Channel channel) {
return channel.exchange("topic_logs", ExchangeType.TOPIC, durable: false);
})
.then((Exchange exchange) {
print(" [*] Waiting for messages in logs. To Exit press CTRL+C");
return exchange.bindPrivateQueueConsumer(routingKeys,
consumerTag: "topic_logs", noAck: true
);
})
.then((Consumer consumer) {
consumer.listen((AmqpMessage event) {
print(" [x] ${event.routingKey}:'${event.payloadAsString}'");
});
});
}