@@ -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