RMQClient(RabbitMQ)获得握手超时错误
问题描述:
我使用pod RMQClient
和pod install
在我的项目中安装RMQClient。然后我import <RMQClient/RMQClient.h>
在ViewController。 根据官方指导,我编写了一些代码,但是当我运行这个项目时,我得到握手超时错误。RMQClient(RabbitMQ)获得握手超时错误
完全错误:
2017-10-17 11:32:06.960214+0800 RMQDemo[1637:557786] Received connection: <RMQConnection: 0x6080000ff780> disconnectedWithError: Error Domain=GCDAsyncSocketErrorDomain Code=8 "Error creating CFStreams" UserInfo={NSLocalizedDescription=Error creating CFStreams}
2017-10-17 11:32:06.963773+0800 RMQDemo[1637:557786] Received connection: <RMQConnection: 0x6000002e1500> disconnectedWithError: Error Domain=kCFStreamErrorDomainSSL Code=-9847 "(null)" UserInfo={NSLocalizedRecoverySuggestion=Error code definition can be found in Apple's SecureTransport.h}
2017-10-17 11:32:16.956467+0800 RMQDemo[1637:557769] Received connection: <RMQConnection: 0x6080000ff780> failedToConnectWithError: Error Domain=com.rabbitmq.rabbitmq-objc-client Code=1 "Handshake timed out." UserInfo={NSLocalizedDescription=Handshake timed out.}
2017-10-17 11:32:16.959851+0800 RMQDemo[1637:557769] Received connection: <RMQConnection: 0x6000002e1500> failedToConnectWithError: Error Domain=com.rabbitmq.rabbitmq-objc-client Code=1 "Handshake timed out." UserInfo={NSLocalizedDescription=Handshake timed out.}
我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self send];
[self receive];
}
- (void)send
{
RMQConnection * conn = [[RMQConnection alloc] initWithUri:@"amqps://username:[email protected]:5672" delegate:[RMQConnectionDelegateLogger new]];
[conn start];
id<RMQChannel>channel = [conn createChannel];
RMQQueue * queue = [channel queue:@"hello"];
[channel.defaultExchange publish:[@"hello world" dataUsingEncoding:NSUTF8StringEncoding] routingKey:queue.name];
[conn close];
}
- (void)receive
{
RMQConnection * conn = [[RMQConnection alloc] initWithUri:@"amqps://username:[email protected]:5672" delegate:[RMQConnectionDelegateLogger new]];
[conn start];
id<RMQChannel>channel = [conn createChannel];
RMQQueue * queue = [channel queue:@"hello"];
[queue subscribe:^(RMQMessage * _Nonnull message) {
NSLog(@"message:%@",[[NSString alloc] initWithData:message.body encoding:NSUTF8StringEncoding]);
}];
[conn close];
}
如何解决这个问题呢?如何使用这个框架?
平台:Xcode中9,iPhone8模拟器,iOS11
答
我检查你的代码,它是相同的网站上的演示代码。
从错误信息中可以看出,创建CFStream时出现错误。根据错误代码-9847,也许该服务现在不工作,请先检查服务状态!
This tutorial assumes RabbitMQ is installed and running on localhost on standard port (5672). In case you use a different host, port or credentials, connections settings would require adjusting.
该服务正在运行。 – ttxoox