AWSSQS 尝试创建队列并获取消息

AWSSQS trying to create queue and get messages

我正在尝试连接到 AWS SQS 以创建一个新队列并获取我放在另一个队列中的消息。这是我正在使用的代码:

    AWSSQS *sqs=[[AWSSQS alloc] initWithConfiguration:configuration];

    AWSSQSCreateQueueRequest *createQueue = [[AWSSQSCreateQueueRequest alloc] init];
    [createQueue setQueueName:@"TEST_Q2_NEW_3"];

    BFTask *answer = [sqs createQueue:createQueue];       
    NSLog(@"Status queue creation: %@ %@", answer.result, answer.error);

    AWSSQSReceiveMessageRequest *receiveMessageRequest = [[AWSSQSReceiveMessageRequest alloc] init];      
    receiveMessageRequest.QueueUrl = @"https://sqs.eu-west-1.amazonaws.com/xxxxxxxxxxxx/TEST_Q";

    answer = [sqs receiveMessage:receiveMessageRequest];
    NSLog(@"Status messages received %@ %@", answer.result, answer.error);

队列 TEST_Q2_NEW_3 已创建,但日志消息为:

状态队列创建:(null) (null)

未提取任何消息,但在 SQS 管理控制台中,一些消息的状态为“正在运行的消息”。但是,日志消息是:

收到的状态消息 (null) (null)

我错过了什么?

原来我没有完全理解BFTasks。声明:

answer = [sqs receiveMessage:receiveMessageRequest];

实际上在后台启动了一个进程,打印日志消息时此任务尚未完成。要继续处理结果,您必须使用 continueWithBlock。接收消息功能的工作代码如下所示:

answer = [sqs receiveMessage:receiveMessageRequest];
[answer continueWithBlock:^id(BFTask *task) {
    if (task.isCancelled) {
        NSLog(@"Status received messages  %@ %@", answer.result, answer.error);
    } else if (task.error) {
        NSLog(@"Status received messages  %@ %@", answer.result, answer.error);
    } else {
        NSLog(@"Status received messages  %@ %@", answer.result, answer.error);
    }
    return nil;
}];

这是我找到答案的地方: BoltsFramework/Bolts-iOS - GitHub