Skip to content

Commit de58579

Browse files
committed
Update objc tutorial1 for async API
[#117323195]
1 parent 5b47ac5 commit de58579

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
github "robbiehanson/CocoaAsyncSocket" "562bae6af6dbd7e1891293dae20b9f79a2fd7228"
22
github "Mantle/Mantle" "cdb82df5dd3a7e4cfab6dfbc48df20dcc80b4e13"
3-
github "rabbitmq/rabbitmq-objc-client" "3e36e6db95769016ea38765ff6255e932867c89d"
3+
github "rabbitmq/rabbitmq-objc-client" "c1e590779041d6775fab41287867e54cbf5fac61"

objective-c/tutorial1/tutorial1/ViewController.m

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,38 @@ @implementation ViewController
88

99
- (void)viewDidLoad {
1010
[super viewDidLoad];
11-
[self send];
1211
[self receive];
12+
sleep(1);
13+
[self send];
1314
}
1415

1516
- (void)send {
1617
NSLog(@"Attempting to connect to local RabbitMQ broker");
17-
RMQConnection *conn = [RMQConnection new];
18-
NSError *error = NULL;
19-
[conn startWithError:&error];
20-
if (error) {
21-
NSLog(@"Couldn't connect to local RabbitMQ broker: %@", error);
22-
exit(1);
23-
}
18+
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
19+
[conn start];
2420

25-
id<RMQChannel> ch = [conn createChannelWithError:&error];
26-
if (error) {
27-
NSLog(@"Error creating channel: %@", error);
28-
[conn close];
29-
exit(1);
30-
}
21+
id<RMQChannel> ch = [conn createChannel];
3122

3223
RMQQueue *q = [ch queue:@"hello"];
24+
3325
[q publish:@"Hello World!"];
3426
NSLog(@"Sent 'Hello World!'");
27+
3528
[conn close];
3629
}
3730

3831
- (void)receive {
3932
NSLog(@"Attempting to connect to local RabbitMQ broker");
40-
RMQConnection *conn = [RMQConnection new];
41-
NSError *error = NULL;
42-
[conn startWithError:&error];
43-
if (error) {
44-
NSLog(@"Couldn't connect to local RabbitMQ broker: %@", error);
45-
exit(1);
46-
}
33+
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
34+
[conn start];
4735

48-
id<RMQChannel> ch = [conn createChannelWithError:&error];
49-
if (error) {
50-
NSLog(@"Error creating channel: %@", error);
51-
[conn close];
52-
exit(1);
53-
}
36+
id<RMQChannel> ch = [conn createChannel];
5437

5538
RMQQueue *q = [ch queue:@"hello"];
5639
NSLog(@"Waiting for messages.");
57-
[q subscribeWithError:&error handler:^(id<RMQMessage> _Nonnull message) {
40+
[q subscribe:^(id<RMQMessage> _Nonnull message) {
5841
NSLog(@"Received %@", message.content);
5942
}];
60-
if (error) {
61-
NSLog(@"Error subscribing: %@", error);
62-
[conn close];
63-
exit(1);
64-
}
6543
}
6644

6745
@end

0 commit comments

Comments
 (0)