@@ -9,6 +9,45 @@ @implementation ViewController
9
9
10
10
- (void )viewDidLoad {
11
11
[super viewDidLoad ];
12
+
13
+ [self receiveLogsTopic: @[@" kern.*" , @" *.critical" ]];
14
+ sleep (1 );
15
+ [self emitLogTopic: @" Hello World!" routingKey: @" kern.info" ];
16
+ [self emitLogTopic: @" A critical kernel error" routingKey: @" kern.critical" ];
17
+ [self emitLogTopic: @" Critical module error" routingKey: @" somemod.critical" ];
18
+ [self emitLogTopic: @" Just some module info. You won't get this." routingKey: @" somemod.info" ];
19
+ }
20
+
21
+ - (void )receiveLogsTopic : (NSArray *)routingKeys {
22
+ RMQConnection *conn = [[RMQConnection alloc ] initWithDelegate: [RMQConnectionDelegateLogger new ]];
23
+ [conn start ];
24
+
25
+ id <RMQChannel> ch = [conn createChannel ];
26
+ RMQExchange *x = [ch topic: @" topic_logs" ];
27
+ RMQQueue *q = [ch queue: @" " options: RMQQueueDeclareExclusive];
28
+
29
+ for (NSString *routingKey in routingKeys) {
30
+ [q bind: x routingKey: routingKey];
31
+ }
32
+
33
+ NSLog (@" Waiting for logs." );
34
+
35
+ [q subscribe: ^(RMQDeliveryInfo * _Nonnull deliveryInfo, RMQMessage * _Nonnull message) {
36
+ NSLog (@" %@ :%@ " , deliveryInfo.routingKey , message.content );
37
+ }];
38
+ }
39
+
40
+ - (void )emitLogTopic : (NSString *)msg routingKey : (NSString *)routingKey {
41
+ RMQConnection *conn = [[RMQConnection alloc ] initWithDelegate: [RMQConnectionDelegateLogger new ]];
42
+ [conn start ];
43
+
44
+ id <RMQChannel> ch = [conn createChannel ];
45
+ RMQExchange *x = [ch topic: @" topic_logs" ];
46
+
47
+ [x publish: msg routingKey: routingKey];
48
+ NSLog (@" Sent '%@ '" , msg);
49
+
50
+ [conn close ];
12
51
}
13
52
14
53
@end
0 commit comments