2012-09-03 6 views
1

작업자 역할에서 서비스 버스 대기열로 메시지를 보내고 있습니다. 나는 무작위로 일부 메시지가 손실 된 것으로 나타났습니다.Azure 서비스 버스 대기열 : 메시지가 전송되지 않습니다.

디버깅 할 때 Send 메서드 다음에 중단 점을 설정하고 Azure Panel에 로그인하여 메시지 큐가 증가했는지 확인합니다. 내가 알게 된 것은 이상하게도 메시지가 대기열에 몇 번 추가되지 않는다는 것입니다. 그러나 그것은 무작위가 아닙니다. 패턴은 다음과 같습니다. 하나의 메시지가 올바르게 추가되고 다음 메시지가 손실 된 후 다시 다음 메시지는 확인되고 다음 메시지는 손실됩니다.

다음과 같은 재 시도 패턴을 구현했지만 분명히 모든 메시지가 올바르게 전송 된 것은 아닙니다.

내 코드는 다음과 같습니다

var baseAddress = RoleEnvironment.GetConfigurationSettingValue("namespaceAddress"); 
var issuerName = RoleEnvironment.GetConfigurationSettingValue("issuerName"); 
var issuerKey = RoleEnvironment.GetConfigurationSettingValue("issuerKey"); 
var retryStrategy = new FixedInterval(5, TimeSpan.FromSeconds(2)); 
var retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy); 
Uri namespaceAddress = ServiceBusEnvironment.CreateServiceUri("sb", baseAddress, string.Empty); 

this.namespaceManager = new NamespaceManager(namespaceAddress, TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerKey)); 
this.messagingFactory = MessagingFactory.Create(namespaceAddress, TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerKey)); 
//namespaceManager.GetQueue("chatmessage"); 
QueueClient client = messagingFactory.CreateQueueClient("chatmessage"); 
APPService.Model.MessageReceived messageReceived = new Model.MessageReceived(); 
messageReceived.From= e.From; 
messageReceived.Op = e.Operator; 
messageReceived.Message = e.Body; 
BrokeredMessage msg = null; 

// Use a retry policy to execute the Send action in an asynchronous and reliable fashion. 
retryPolicy.ExecuteAction 
(
    (cb) => 
    { 
     // A new BrokeredMessage instance must be created each time we send it. Reusing the original BrokeredMessage instance may not 
     // work as the state of its BodyStream cannot be guaranteed to be readable from the beginning. 
     msg = new BrokeredMessage(messageReceived); 

     // Send the event asynchronously. 
     client.BeginSend(msg, cb, null); 
    }, 
    (ar) => 
    { 
     try 
     { 
      // Complete the asynchronous operation. This may throw an exception that will be handled internally by the retry policy. 
      client.EndSend(ar); 
     } 
     finally 
     { 
      // Ensure that any resources allocated by a BrokeredMessage instance are released. 
      if (msg != null) 
      { 
       msg.Dispose(); 
       msg = null; 
      } 
     } 
    }, 
    ()=>{}, 
    (ex) => 
    { 
     // Always dispose the BrokeredMessage instance even if the send operation has completed unsuccessfully. 
     if (msg != null) 
     { 
      msg.Dispose(); 
      msg = null; 
     } 

     // Always log exceptions. 
     Trace.TraceError(ex.Message); 
    } 
); 

은 무엇 잘못 될 수 있을까?

+0

'''qc.SendAsync'를 기다린 후에 메시지를 보내면 메시지가 전송되지 않는 것을 발견했습니다. – mcintyre321

답변

1

코드를 보면 클라우드가 문제를 일으킬 수 있음을 알 수 없습니다. 포털의 카운터가 실시간으로 업데이트되지 않기 때문에 테스트 결과로 간주하지 않을 것입니다.

나는 지금 당장 도움이되지 않는다는 것을 알고 있습니다.하지만 당신이 표현하는 것이 의심 스럽다면 나는 messageId를 비교하면서 메시지를 보내고받을 수있는 종합적인 테스트를 만들 것입니다.

MSDN의 Paolo Salvatori가 이미 Service Bus Explorer을 사용하고 있습니까? 엔티티를 테스트하는 데 사용할 수 있습니다. 서비스 버스를 탐색하고 테스트 할 수있는 신뢰할 수있는 도구입니다.

+0

감사합니다. 서비스 버스 탐색기를 확인해 보겠습니다. –

관련 문제