2014-05-11 3 views
1

Hy,Windows 서비스 버스 LockDuration 속성 값이

LockDuration 속성에 관한 질문이 있습니다. 나는이 기능을 가지고있다 :

// Use the MessagingFactory to create a queue client for the orderqueue. 
QueueClient queueClient = factory.CreateQueueClient("orderqueue"); 

// Receive messages from the queue with a 10 second timeout. 
while (true) 
{ 
    // Receive a message using a 10 second timeout 
    BrokeredMessage msg = queueClient.Receive(TimeSpan.FromSeconds(10)); 

    if (msg != null) 
    { 
     // Deserialize the message body to an order data contract. 
     Order order = msg.GetBody<Order>(); 
     // Output the order. 
     Console.WriteLine("{0} {1} {2} {3} {4} ${5}", 
     order.OrderNumber, 
     order.Customer.FirstName, 
     order.Customer.LastName, 
     order.ShipTo.City, 
     order.ShipTo.Province, 
     order.Total); 
     // Update the database 
     try 
     { 
      // Add the order to the database. 
      OrdersData.AddOrder(order); 
      // Mark the message as complete. 
      msg.Complete(); 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine("Exception: {0}", ex.Message); 
      // Something went wrong, abandon the message. 
      msg.Abandon(); 
     } 
    } 
    else 
    { 
     // No message has been received, we will poll for more messages. 
     Console.WriteLine("Polling, polling, polling..."); 
    } 
} 

위의 예와 같은 메시지가 나는 경우. 모든 것이 정상이면 Complete() 함수를 사용하여 메시지를 삭제합니다. 문제가 발생하면 Abondon() 함수를 호출하여 메시지가 잠금 해제됩니다. 그래서 내 퀴즈 :

peeklock recevie 모드를 사용할 때 메시지의 잠금 기간을 설정하려면 QueueDescription.LockDuration 속성과 SubscriptionDescription.LockDuration 속성이 있습니다. 5 분으로 변경할 수 있습니다. 내가 읽은 곳 어디에서나이 신실함의 가치를주의 깊게 설정해야합니다. abandom() 함수에 오류가있는 경우 메시지가 잠기지 않기 때문에 5 분으로 설정하지 않아야합니다 (코드 예제의 catch 블록 참조). 잠금 기간을 결정하는

안부

+0

나는 어디에서 읽었는지 모르겠다. 5 분 동안 TimeSpan을 잠그지 마라. 그리고 너는 그것을 사용하는 것을 귀찮게한다. PeekLock을 사용할 때의 함축적 인 의미가 있으며 "reliable message receive loops 구현"이라는 멋진 글의 개요가 있습니다. http://msdn.microsoft.com/en-us/library/hh851750.aspx – astaykov

답변

2

주요 고려 사항은 다음과 같습니다

당신이 실패 할 경우에 대한 읽기 얼마나 지연

1)?

2) 메시지를 처리하는 데 시간이 얼마나 걸립니까?

잠금 기간을 5 분으로 설정 한 다음 메시지를 잠그면 프로세서가 작동하지 않는다고 가정합니다. 즉, 5 분 후에 다음 수신자가 메시지를 사용할 수 있습니다. 실패가없고 메시지를 완료하거나 버리면 즉시 사용할 수 있습니다.

메시지를 처리하는 데 거의 1 분이 소요된다고 가정하면 잠금 기간을 2 분으로 설정하고 잠금을 갱신하지 않아도되지만 처리하는 데 10 분이 필요할 경우 RenewLock을 적절히 호출해야합니다. 따라서 첫 번째 사례 (실패의 경우 대기 시간)에 대해별로 신경 쓰지 않고 메시지 처리가 항상 5 분 내에 완료 될 수있는 잠금을 갱신하지 않으려는 경우 5 분을 선택하는 것이 좋습니다.

+0

답장을 보내 주셔서 감사합니다. – user2644964

관련 문제