Skip to content

Instantly share code, notes, and snippets.

@camelpunch
Created August 12, 2016 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camelpunch/800d21f50d6dbc0eb39627a2b866bdf3 to your computer and use it in GitHub Desktop.
Save camelpunch/800d21f50d6dbc0eb39627a2b866bdf3 to your computer and use it in GitHub Desktop.
#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