rabbitmq-tutorials/objective-c/tutorial3/tutorial3/ViewController.m
Andrew Bruce 55315a12bc Update ObjC tutorials for v0.9.0
Also, bump their CocoaAsyncSocket versions.

[#126987947]
2016-07-25 17:13:24 +01:00

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