0

ここにサンプルコード

public override void Run()
{
   while (true)
   {
    IAsyncResult result = CUDClient.BeginReceive(TimeSpan.FromSeconds(10),  OnMessageReceive, CUDClient);
    Thread.Sleep(10000);
   }
}

I have tested this Azure worker role. I kept 100 messages in the Service bus Queue. It's doing entities updates as a operation(Entity framework). It took 15 minutes to process all the queues and looks like taking longer time. Any suggestion to improve this?

Thanks in Advance

4

4 に答える 4

1

メッセージの読み取りを処理するには、XecMeParallelタスクを使用してみてください。

XecMe @ xecme.codeplex.com

于 2013-02-17T20:30:13.150 に答える
1

実際、私の経験では Service Bus は非常に高速です。「Thread.Sleep(10000)」が問題です。

メッセージごとに 10 秒間スリープします。100 メッセージの場合 100*10 = 10000 秒 = 16.67 分 したがって、これは遅延の問題です...

解決:

Thread.Sleep(10000); を使用しないでください。(BeginReceive には適していません。Receive のみに適しています)

public override void Run() //This should not be a Thread...If its a thread then your thread will terminate after receiving your first message
{
    IAsyncResult result = CUDClient.BeginReceive(**TimeSpan.MaxValue**,  OnMessageReceive, CUDClient);
}

//Function OnMessageReceive
{
 //Process the Message
 **IAsyncResult result = CUDClient.BeginReceive(TimeSpan.MaxValue,  OnMessageReceive, CUDClient);**
}

TimeSpan.MaxValue を使用すると、SB への接続が長時間維持されます。したがって、頻繁なヌルメッセージはありません(コストがかかりません)...

于 2013-01-24T14:48:39.020 に答える
0

これを試してみてください...

  //Somefunction
    IAsyncResult result = CUDClient.BeginReceive(OnMessageReceive, CUDClient); 

    while (true)
        Thread.Sleep(1000); //In case you are using thread

    //Somefunction End

public static void OnMessageReceive(IAsyncResult result)
    {
        CUDClient.BeginReceive(OnMessageReceive, CUDClient);
        SubscriptionClient queueClient = (SubscriptionClient)result.AsyncState;
        IBusinessLogicProvider Obj;
        try
        {
            //Receive the message with the EndReceive call
            BrokeredMessage receivedmsg = queueClient.EndReceive(result);
                //receivedmsg = CUDClient.Receive();
                if (receivedmsg != null)
                {
                    switch (receivedmsg.ContentType)
                    {
                        case "Project":
                            Obj = new ProjectsBL();
                            Obj.HandleMessage(receivedmsg);
                            receivedmsg.BeginComplete(OnMessageComplete, receivedmsg);
                            break;
                     }
                 }
          }
    }
于 2013-01-29T08:55:20.893 に答える
0

これを試しました。

while (true)
        {
           //read all topic messages in sequential way....           
           IAsyncResult result = CUDClient.BeginReceive(OnMessageReceive, CUDClient); 
           Thread.Sleep(1000);
        }  
public static void OnMessageReceive(IAsyncResult result)
    {
        SubscriptionClient queueClient = (SubscriptionClient)result.AsyncState;
        IBusinessLogicProvider Obj;
        try
        {
            //Receive the message with the EndReceive call
            BrokeredMessage receivedmsg = queueClient.EndReceive(result);
                //receivedmsg = CUDClient.Receive();
                if (receivedmsg != null)
                {
                    switch (receivedmsg.ContentType)
                    {
                        case "Project":
                            Obj = new ProjectsBL();
                            Obj.HandleMessage(receivedmsg);
                            receivedmsg.BeginComplete(OnMessageComplete, receivedmsg);
                            break;
                     }
                 }
          }
    }

100 件のメッセージすべてを 1 分間 (00:01:02) で処理しました。以前のものよりもはるかに優れています。

于 2013-01-28T08:37:41.777 に答える