2017-10-17 158 views
0

我使用pod RMQClientpod 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

回答

0

我檢查你的代碼,它是相同的網站上的演示代碼。

從錯誤信息中可以看出,創建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.

+0

該服務正在運行。 – ttxoox