当队列中没有消息时拉得极慢

时间:2015-06-01 02:25:45

标签: google-cloud-pubsub

我正在使用带有Gmail的pubsub进行推送通知。

pubsub订阅按预期收到邮件。

当我拉消息时,我注意到如果没有消息可以拉动延迟获得响应非常慢。

如果至少有一条消息需要提取,那么响应是及时的

还有其他人经历过这个吗?

我唯一能解决的问题就是在队列中留言。

if (credential.RequestAccessTokenAsync(CancellationToken.None).Result)
{
    var pubsubSerivce = new Google.Apis.Pubsub.v1beta2.PubsubService(
    new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "iLink",
    });

    PullRequest pr = new PullRequest();
    pr.MaxMessages = 100;
    PullResponse prs = pubsubSerivce.Projects.Subscriptions.Pull(pr, "projects/vivid-canyon-90023/subscriptions/iLink").Execute();

    AcknowledgeRequest ak = new AcknowledgeRequest();

    if (prs != null && prs.ReceivedMessages != null)
    {                    
        ak.AckIds = new List<string>();
        string messageText = "";
        foreach (ReceivedMessage rm in prs.ReceivedMessages)
        {
            ak.AckIds.Add(rm.AckId);
            messageText += " | " + rm.Message.Data;
        }
        pubsubSerivce.Projects.Subscriptions.Acknowledge(ak, "projects/vivid-canyon-90023/subscriptions/iLink").Execute();
        Master.setSuccessPrompt("Pulled Total Meesage count of: " + prs.ReceivedMessages.Count + " | Data | " + messageText);
    }
    else
    {
        Master.setSuccessPrompt("No Messages to pull");
    }
}    

1 个答案:

答案 0 :(得分:2)

这并不慢,只是挂着并等待任何消息。尝试使用returnImmediately = true。