8000 Reinstate separate connections in ObjC 4 & 5 · syk-coder/rabbitmq-tutorials@0247d67 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 0247d67

Browse files
committed
Reinstate separate connections in ObjC 4 & 5
It seems that a local broker is delaying its basic.delivers. Before I noticed this, I'd assumed that using separate connections was causing a race of some sort. [#120637007]
1 parent 3d56cb2 commit 0247d67

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

objective-c/tutorial4/tutorial4/ViewController.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ @implementation ViewController
99

1010
- (void)viewDidLoad {
1111
[super viewDidLoad];
12-
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
13-
[conn start];
1412

15-
[self receiveLogsDirect:conn];
13+
[self receiveLogsDirect];
1614
sleep(2);
17-
[self emitLogDirect:conn message:@"Hello World!" severity:@"info"];
18-
[self emitLogDirect:conn message:@"Missile button pressed" severity:@"warning"];
19-
[self emitLogDirect:conn message:@"Launch mechanism jammed" severity:@"error"];
15+
[self emitLogDirect:@"Hello World!" severity:@"info"];
16+
[self emitLogDirect:@"Missile button pressed" severity:@"warning"];
17+
[self emitLogDirect:@"Launch mechanism jammed" severity:@"error"];
2018
}
2119

22-
- (void)receiveLogsDirect:(RMQConnection *)conn {
20+
- (void)receiveLogsDirect {
21+
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
22+
[conn start];
23+
2324
id<RMQChannel> ch = [conn createChannel];
2425
RMQExchange *x = [ch direct:@"direct_logs"];
2526
RMQQueue *q = [ch queue:@"" options:RMQQueueDeclareExclusive];
@@ -36,7 +37,10 @@ - (void)receiveLogsDirect:(RMQConnection *)conn {
3637
}];
3738
}
3839

39-
- (void)emitLogDirect:(RMQConnection *)conn message:(NSString *)msg severity:(NSString *)severity {
40+
- (void)emitLogDirect:(NSString *)msg severity:(NSString *)severity {
41+
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
42+
[conn start];
43+
4044
id<RMQChannel> ch = [conn createChannel];
4145
RMQExchange *x = [ch direct:@"direct_logs"];
4246

objective-c/tutorial5/tutorial5/ViewController.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ @implementation ViewController
99

1010
- (void)viewDidLoad {
1111
[super viewDidLoad];
12-
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
13-
[conn start];
1412

15-
[self receiveLogsTopic:conn routingKeys:@[@"kern.*", @"*.critical"]];
13+
[self receiveLogsTopic:@[@"kern.*", @"*.critical"]];
1614
sleep(2);
17-
[self emitLogTopic:conn message:@"Hello World!" routingKey:@"kern.info"];
18-
[self emitLogTopic:conn message:@"A critical kernel error" routingKey:@"kern.critical"];
19-
[self emitLogTopic:conn message:@"Critical module error" routingKey:@"somemod.critical"];
20-
[self emitLogTopic:conn message:@"Just some module info. You won't get this." routingKey:@"somemod.info"];
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"];
2119
}
2220

23-
- (void)receiveLogsTopic:(RMQConnection *)conn routingKeys:(NSArray *)routingKeys {
21+
- (void)receiveLogsTopic:(NSArray *)routingKeys {
22+
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
23+
[conn start];
24+
2425
id<RMQChannel> ch = [conn createChannel];
2526
RMQExchange *x = [ch topic:@"topic_logs"];
2627
RMQQueue *q = [ch queue:@"" options:RMQQueueDeclareExclusive];
@@ -36,7 +37,10 @@ - (void)receiveLogsTopic:(RMQConnection *)conn routingKeys:(NSArray *)routingKey
3637
}];
3738
}
3839

39-
- (void)emitLogTopic:(RMQConnection *)conn message:(NSString *)msg routingKey:(NSString *)routingKey {
40+
- (void)emitLogTopic:(NSString *)msg routingKey:(NSString *)routingKey {
41+
RMQConnection *conn = [[RMQConnection alloc] initWithDelegate:[RMQConnectionDelegateLogger new]];
42+
[conn start];
43+
4044
id<RMQChannel> ch = [conn createChannel];
4145
RMQExchange *x = [ch topic:@"topic_logs"];
4246

0 commit comments

Comments
 (0)
0