51 lines
1.1 KiB
Objective-C
51 lines
1.1 KiB
Objective-C
#import "ViewController.h"
|
|
@import RMQClient;
|
|
|
|
@interface ViewController ()
|
|
|
|
@end
|
|
|
|
@implementation ViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self receiveLogs];
|
|
[self receiveLogs];
|
|
sleep(1);
|
|
[self emitLog];
|
|
}
|
|
|
|
- (void)emitLog {
|
|
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
|
|
[conn start];
|
|
|
|
id<RMQChannel> ch = [conn createChannel];
|
|
RMQExchange *x = [ch fanout:@"logs"];
|
|
|
|
NSString *msg = @"Hello World!";
|
|
|
|
[x publish:[msg dataUsingEncoding:NSUTF8StringEncoding]];
|
|
NSLog(@"Sent %@", msg);
|
|
|
|
[conn close];
|
|
}
|
|
|
|
- (void)receiveLogs {
|
|
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
|
|
[conn start];
|
|
|
|
id<RMQChannel> ch = [conn createChannel];
|
|
RMQExchange *x = [ch fanout:@"logs"];
|
|
RMQQueue *q = [ch queue:@"" options:RMQQueueDeclareExclusive];
|
|
|
|
[q bind:x];
|
|
|
|
NSLog(@"Waiting for logs.");
|
|
|
|
[q subscribe:^(RMQMessage * _Nonnull message) {
|
|
NSLog(@"Received %@", [[NSString alloc] initWithData:message.body encoding:NSUTF8StringEncoding]);
|
|
}];
|
|
}
|
|
|
|
@end
|