8000 Tutorial 3 controller for Objective-C · zerolugithub/rabbitmq-tutorials@cc1581c · GitHub
[go: up one dir, main page]

Skip 8000 to content

Commit cc1581c

Browse files
committed
Tutorial 3 controller for Objective-C
[#117056895]
1 parent 8424070 commit cc1581c

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
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" "a16d18f635b3ba1ffb01d27d4393ee97cadf4f34"
3-
github "rabbitmq/rabbitmq-objc-client" "ea25de2d8d43152f8040d0994a9a3a4239d9442f"
3+
github "rabbitmq/rabbitmq-objc-client" "de0f201af7d3fd94f62ef29568c83ab88b2b35fb"
Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
//
2-
// ViewController.m
3-
// tutorial3
4-
//
5-
// Created by Pivotal on 25/04/2016.
6-
// Copyright © 2016 RabbitMQ. All rights reserved.
7-
//
8-
91
#import "ViewController.h"
102
@import RMQClient;
113

@@ -17,12 +9,42 @@ @implementation ViewController
179

1810
- (void)viewDidLoad {
1911
[super viewDidLoad];
20-
// Do any additional setup after loading the view, typically from a nib.
12+
[self receiveLogs];
13+
[self receiveLogs];
14+
sleep(1);
15+
[self emitLog];
2116
}
2217

23-
- (void)didReceiveMemoryWarning {
24-
[super didReceiveMemoryWarning];
25-
// Dispose of any resources that can be recreated.
18+
- (void)emitLog {
19+
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
20+
[conn start];
21+
22+
id<RMQChannel> ch = [conn createChannel];
23+
RMQExchange *x = [ch fanout:@"logs" options:RMQExchangeDeclareNoOptions];
24+
25+
NSString *msg = @"Hello World!";
26+
27+
[x publish:msg];
28+
NSLog(@"Sent %@", msg);
29+
30+
[conn close];
31+
}
32+
33+
- (void)receiveLogs {
34+
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
35+
[conn start];
36+
37+
id<RMQChannel> ch = [conn createChannel];
38+
RMQExchange *x = [ch fanout:@"logs" options:RMQExchangeDeclareNoOptions];
39+
RMQQueue *q = [ch queue:@"" options:RMQQueueDeclareExclusive];
40+
41+
[q bind:x];
42+
43+
NSLog(@"Waiting for logs.");
44+
45+
[q subscribe:^(RMQMessage * _Nonnull message) {
46+
NSLog(@"Received %@", message);
47+
}];
2648
}
2749

2850
@end

0 commit comments

Comments
 (0)
0