Created
August 12, 2016 11:19
-
-
Save camelpunch/800d21f50d6dbc0eb39627a2b866bdf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
@import RMQClient; | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// running /usr/local/sbin/rabbitmq-server from terminal | |
[self send]; | |
[self receive]; | |
} | |
- (void)send { | |
NSLog(@"Attempting to connect to local RabbitMQ broker"); | |
RMQConnection *conn = [[RMQConnection alloc] initWithUri:@"amqp://guest:guest@localhost" delegate:[RMQConnectionDelegateLogger new]]; | |
[conn start]; | |
id<RMQChannel> ch = [conn createChannel]; | |
RMQQueue *q = [ch queue:@"hello"]; | |
[ch.defaultExchange publish:[@"Hello World!" dataUsingEncoding:NSUTF8StringEncoding] routingKey:q.name]; | |
NSLog(@"Sent 'Hello World!'"); | |
[conn close]; | |
} | |
- (void)receive { | |
NSLog(@"Attempting to connect to local RabbitMQ broker"); | |
RMQConnection *conn = [[RMQConnection alloc] initWithUri:@"amqp://guest:guest@localhost" delegate:[RMQConnectionDelegateLogger new]]; | |
[conn start]; | |
id<RMQChannel> ch = [conn createChannel]; | |
RMQQueue *q = [ch queue:@"hello"]; | |
NSLog(@"Waiting for messages."); | |
[q subscribe:^(RMQMessage * _Nonnull message) { | |
NSLog(@"Received %@", [[NSString alloc] initWithData:message.body encoding:NSUTF8StringEncoding]); | |
}]; | |
NSLog(@"end of receiving"); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment