2012-12-27 37 views
2

我開發iOS應用程序,並使用profmaad的Objective-C的客戶端的RabbitMQ https://github.com/profmaad/librabbitmq-objc的Objective-C的RabbitMQ客戶沒有收到消息

這是我用來建立連接並開始監聽事件代碼:

-(void)establish{ 

    AMQPConnection *connection = [[AMQPConnection alloc] init]; 
    [connection connectToHost:<host> onPort:<port number>]; 
    [connection loginAsUser:<username> withPasswort:<password> onVHost:<vHost>]; 

    AMQPChannel *channel = [connection openChannel]; 
    AMQPQueue *queue = [[AMQPQueue alloc] initWithName:<queue name> onChannel:channel isPassive:NO isExclusive:NO isDurable:NO getsAutoDeleted:NO]; 

    AMQPConsumer *consumer = [[AMQPConsumer alloc] initForQueue:queue onChannel:channel useAcknowledgements:YES isExclusive:NO receiveLocalMessages:NO]; 
    AMQPConsumerThread *consumerThread = [[AMQPConsumerThread alloc] initWithConsumer:consumer]; 
    consumerThread.delegate = self; 
} 
-(void)amqpConsumerThreadReceivedNewMessage:(AMQPMessage *)theMessage 
{ 
    NSLog(@"message = %@", theMessage); 
    NSLog(@"message.body = %@", theMessage.body); 
} 

問題是,amqpConsumerThreadReceivedNewMessage永遠不會被調用!

回答

3

您需要先啓動消費者線程。

[consumerThread start];