pod 'RMQClient'
#import <RMQClient/RMQClient.h>
- (void)viewDidLoad {
[super viewDidLoad];
NSString *url = @"amqp://admin:123456@192.168.xx.xx:5672/";
RMQConnection *conn = [[RMQConnection alloc] initWithUri:url delegate:self];
[conn start];
id<RMQChannel>channel = [conn createChannel];
//RMQExchange *x = [channel fanout:@"deviceStop" options:RMQExchangeDeclareDurable];
RMQQueue *queue = [channel queue:@"deviceStop"];
//[queue bind:x];
[queue subscribe:^(RMQMessage * _Nonnull message) {
NSLog(@"%@",[[NSString alloc] initWithData:message.body encoding:NSUTF8StringEncoding]);
}];
}
- (void)connection:(RMQConnection *)connection failedToConnectWithError:(NSError *)error{
NSLog(@"----链接失败");
}
- (void) connection:(RMQConnection *)connection
disconnectedWithError:(NSError *)error{
NSLog(@"------失去链接");
NSLog(@"------失去链接------%ld",_second);
}
/// @brief Called before the configured <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a> sleep.
- (void)willStartRecoveryWithConnection:(RMQConnection *)connection{
NSLog(@"------开始恢复链接");
}
/// @brief Called after the configured <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a> sleep.
- (void)startingRecoveryWithConnection:(RMQConnection *)connection{
NSLog(@"------恢复中");
}
/*!
* @brief Called when <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a> has succeeded.
* @param RMQConnection the connection instance that was recovered.
*/
- (void)recoveredConnection:(RMQConnection *)connection{
NSLog(@"------链接恢复成功");
NSLog(@"------链接恢复成功------%ld",_second);
}
/// @brief Called with any channel-level AMQP exception.
- (void)channel:(id<RMQChannel>)channel
error:(NSError *)error{
NSLog(@"------链接过程信道异常");
}