작업자 역할에서 서비스 버스 대기열로 메시지를 보내고 있습니다. 나는 무작위로 일부 메시지가 손실 된 것으로 나타났습니다.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);
}
);
은 무엇 잘못 될 수 있을까?
'''qc.SendAsync'를 기다린 후에 메시지를 보내면 메시지가 전송되지 않는 것을 발견했습니다. – mcintyre321