-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRabbitMQClient.m
More file actions
62 lines (47 loc) · 1.39 KB
/
RabbitMQClient.m
File metadata and controls
62 lines (47 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// RabbitMQClient.m
// MuseStatsIos
//
// Created by Felipe Valdez on 11/19/15.
// Copyright © 2015 InteraXon. All rights reserved.
//
#import "RabbitMQClient.h"
#import "AMQPExchange.h"
#import "AMQPConnection.h"
#import "Constants.h"
@implementation RabbitMQClient
+ (RabbitMQClient*)sharedClient {
static RabbitMQClient *client = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
client = [[self alloc] init];
});
return client;
}
-(id)init
{
self = [super init];
if (self) {
self.connection = [[AMQPConnection alloc] init];
}
return self;
}
-(void)setupWithExchangeName:(NSString*)exchangeName
{
@try {
[self.connection connectToHost:kHostName onPort:kPortNumber];
[self.connection loginAsUser:kExchangeUsername withPasswort:kExchangePassword onVHost:@"/"];
AMQPChannel *channel = [self.connection openChannel];
self.exchange = [[AMQPExchange alloc] initDirectExchangeWithName:exchangeName onChannel:channel isPassive:YES isDurable:NO getsAutoDeleted:NO];
}
@catch (NSException *exception) {
NSLog(@"exception: %@",exception);
}
@finally {
}
}
-(void)sendData:(NSString *)payload OnExchangeName:(NSString*)exchangeName
{
[self.exchange publishMessage:payload usingRoutingKey:exchangeName];
}
@end