当队列中没有消息时,拉取速度极慢
Pull extremely slow when no messages on queue
我将 pubsub 与 Gmail 一起用于推送通知。
pubsub 订阅按预期接收消息。
然而,当我提取消息时,我注意到如果没有要提取的消息,获得响应的延迟会非常慢。
如果至少有 1 条消息需要拉取,那么响应是及时的
有没有其他人遇到过这种情况?
我唯一能想到的解决方法是在队列中留言。
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");
}
}
这并不慢,只是挂起并等待任何消息。尝试使用 returnImmediately=true.
我将 pubsub 与 Gmail 一起用于推送通知。
pubsub 订阅按预期接收消息。
然而,当我提取消息时,我注意到如果没有要提取的消息,获得响应的延迟会非常慢。
如果至少有 1 条消息需要拉取,那么响应是及时的
有没有其他人遇到过这种情况?
我唯一能想到的解决方法是在队列中留言。
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");
}
}
这并不慢,只是挂起并等待任何消息。尝试使用 returnImmediately=true.