2

我正在尝试构建一个事件驱动的 Azure 队列,每次将消息放入 Azure 队列时都会触发一个事件。使用 AzureXplorer,我看到消息已正确放入 Azure 队列,但 CloudQueueClient.ResponseReceived 事件永远不会触发。我正在使用 Azure V1.4。这是我的 Worker 角色的代码:

public class WorkerRole : RoleEntryPoint
{
    public override void Run()
    {            
        while (true)
        {
            Thread.Sleep(10000);

        }
    }

    public override bool OnStart()
    {
        // Set the maximum number of concurrent connections 
        ServicePointManager.DefaultConnectionLimit = 12;

        var queuDataSource = new AzureQueueDataSource();
        queuDataSource.GetCloudQueueClient().ResponseReceived +=new EventHandler<ResponseReceivedEventArgs>(WorkerRole_ResponseReceived);


        // For information on handling configuration changes
        // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
        return base.OnStart();
    }

    void WorkerRole_ResponseReceived(object sender, ResponseReceivedEventArgs e)
    {
        var i = 1;  // Breakpoint here never happends
    }
}
4

1 回答 1

4

需要轮询 Windows Azure 队列以获取新消息。有关如何查询队列以获取新消息的示例,请参阅此处的SDK 示例或代码。

要考虑的事项的快速列表:

  1. 因为轮询在 Windows Azure 中被视为交易,所以您需要为此付费。
  2. 如果没有找到消息,通常最好实现某种重试机制(例如指数退避等)
  3. 批量检索消息通常很好(更少的往返,更少的事务等)
  4. 请记住,消息可以多次传递(计划重复消息)
  5. 使用“ dequeuecount ”属性来处理“毒消息”。

所有这些都有很多报道。请参阅上面链接中的文档/示例。这篇文章也很不错:http: //blogs.msdn.com/b/appfabriccat/archive/2010/12/20/best-practices-for-maximizing-scalability-and-cost-effectiveness-of-queue-based -messaging-solutions-on-windows-azure.aspx

于 2011-03-27T18:02:05.760 回答