self.connection = [[AMQPConnection alloc] initWithHost:mqAddress port:mqPort
heartbeat:mqHeartbeat userName:userName
password:password vHost:mqVHost lifecycleDelegate:self];
self.connection.isLogin = FALSE;
self.connection.maxFrame = 65536;//64k
self.connection.readTimeout = 15;
NSError *error;
BOOL isSuccess = [self.connection connectionWithTimeout:3 error:&error];
if (isSuccess) {
[self.connection startHeartbeat];//Yes, we keep a heartbeat
}
- (void)handleDelivery:(NSString *)consumerTag envelope:(Envelope *)envelope properties:(AMQPBasicProperties *)properties
body:(NSData *)body {
NSError *error = nil;
NSLog(@"get message, length: %tu, type: %@", body.length, properties.contentType);
if (![@"msg" isEqualToString:properties.contentType]) {
[self.channel basicNAck:envelope.deliveryTag multiple:FALSE requeue:FALSE error:&error];
return;
}
//...... PostSomeNotification(body);
[self.channel basicAck:envelope.deliveryTag multiple:FALSE error:&error];
}
- (instancetype)initWith:(AMQPChannel *)channel {
self = [super init];
if (self) {
self.channel = channel;
}
return self;
}
NSString *consumeTag = [self.channel basicConsume:consumerQueue_ autoAck:FALSE delegate:consumer error:&error];