1

Worker ロールから Service Bus Queue にメッセージを送信しています。いくつかのメッセージがランダムに失われていることに気付きました。

デバッグするときは、Send メソッドの後にブレークポイントを設定し、Azure Panel にログインして、メッセージ キューが増加したかどうかを確認します。私が見つけたのは、奇妙なことに、メッセージがキューに追加されない場合があるということです。しかし、それはランダムではありません。パターンは次のとおりです。1 つのメッセージが正しく追加され、次のメッセージが失われ、次のメッセージは問題なく追加され、次のメッセージが失われます。

次のような再試行パターンを実装しましたが、すべてのメッセージが正しく送信されているわけではないようです。

私のコードは次のとおりです。

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);
    }
);

何が間違っている可能性がありますか?

4

1 に答える 1

2

あなたのコードを見るだけで、クラウドが問題につながることに気付くことができません。ポータルのカウンターはリアルタイムで更新されていないので、テスト結果とは見なしません。

私は今助けていないことを知っていますが、あなたが表明していることに疑問がある場合は、メッセージを送受信するためのエンドツーエンドのテストを作成し、messageId を比較します。

MSDN の Paolo Salvatori によるService Bus Explorerを既に使用していますか? これを使用してエンティティをテストできます。これは、Service Bus を調査およびテストするための信頼できるツールです。

于 2012-09-04T07:48:41.287 に答える