Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
确定Azure存储队列中是否有消息的最有效方法_Azure_Azure Storage - Fatal编程技术网

确定Azure存储队列中是否有消息的最有效方法

确定Azure存储队列中是否有消息的最有效方法,azure,azure-storage,Azure,Azure Storage,我正在开始一个涉及Azure队列(而不是服务总线)的项目。 我正在试图找出找出队列中是否有消息等待的最佳做法 好的,有两种方法: 使用队列对象的ApproximateMessageCount属性 调用GetMessage,如果返回值为null,则没有消息 哪一个性能更好?有什么区别吗 从计费POV中,我了解到他们都有交易成本,对吗 谢谢 我过去也使用过此代码: var cnnString = "the connection string"; var queueName = "the queue

我正在开始一个涉及Azure队列(而不是服务总线)的项目。 我正在试图找出找出队列中是否有消息等待的最佳做法

好的,有两种方法:

  • 使用队列对象的ApproximateMessageCount属性
  • 调用GetMessage,如果返回值为null,则没有消息
  • 哪一个性能更好?有什么区别吗

    从计费POV中,我了解到他们都有交易成本,对吗


    谢谢

    我过去也使用过此代码:

    var cnnString = "the connection string";
    var queueName = "the queue name";
    
    var nsManager = NamespaceManager.CreateFromConnectionString(cnnString);
    return nsManager.GetQueue(queueName).MessageCount;
    
    也就是说,这是大约4个月前的事


    您需要这样做的任何原因(即,您不仅仅是在队列中消费消息吗?

    GetMessage既快又便宜。从逻辑角度来看,GetMessage也更为正确,因为消息计数将返回已被另一个读卡器检索的消息以及已过期但未被删除的消息。

    主要原因是性能。我想使用更快、更少的资源密集型方法,我不确定这些方法之间是否存在差异。性能与什么相比?我仍然有点不清楚您想要实现什么(是的,计算队列中的消息…但是为什么?)好的,让我澄清一下:我想检查队列中是否有消息,如果有,那么-获取第一条消息。第一种方法是调用GetMessage,如果为空,它将返回null。第二个选项是调用ApproximateMessageCount,如果数字大于0,则获取消息。我的问题是-当队列为空时,哪个选项的性能更好?