我使用pod RMQClient
和pod install
在我的项目中安装 RMQClient 。然后我在 ViewController 中import <RMQClient/RMQClient.h>
。
根据官方指导,我写了一些代码,但是当我运行这个项目时,我得到 Handshake outd out 错误。
完全错误:
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:password@192.168.x.x: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:password@192.168.x.x: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
答案 0 :(得分:0)
我检查了你的代码,它与网站上的演示代码相同。
从错误信息中,它说创建CFStreams时出错了。根据错误代码-9847,可能该服务现在无法正常工作,请先检查服务状态!
本教程假设RabbitMQ已在localhost上安装并运行 在标准端口(5672)上。如果您使用不同的主机,端口或 凭据,连接设置需要调整。