Objective-C RabbitMQ客户端无法接收消息

时间:2012-12-27 17:18:01

标签: iphone ios xcode rabbitmq

我正在开发一个iOS应用程序并使用profmaad的objective-c客户端用于RabbitMQ https://github.com/profmaad/librabbitmq-objc

这是我用来建立连接并开始收听事件的代码:

-(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!

1 个答案:

答案 0 :(得分:3)

您需要先启动使用者线程。

[consumerThread start];