1

トピック/サブスクリプションを使用するクラウド サービス用の SQL フィルターを作成しています。次のような仲介メッセージのプロパティを宣言しました

BrokeredMessage message = new BrokeredMessage("Response Message#"+ (++counter) +" Body");

// Set additional custom app-specific property
message.Properties["MsgGUID"] = RequestMessageID; //assign msgGUID read from the Azure Queue

// Send message to the topic
Client.Send(message);

達成したいのは、ワーカーロールにメッセージを送信すると、メッセージにランダムに生成された文字列が含まれることです。Worker ロールはその文字列を ID として扱い、ブローカー メッセージを作成します。このメッセージの "MsgGUID" プロパティに ID が保持されます。私のSQLフィルターは次のようになります:

SqlFilter CompareGUIDFilter = new SqlFilter("MsgGUID = '" + messageID + "'");//Filter based on the Requested GUID i.e. msgGUID

if (!nameSpaceManager.SubscriptionExists("TestTopic", "RequestMessageGUIDSubscriber"))
            {
                /*Subscriber with Filter as Receive only those Messages from the Topic that are 
                requested by the controller from another RequestQueue(Azure Queue) with GUID as messageID*/
                nameSpaceManager.CreateSubscription("TestTopic", "RequestMessageGUIDSubscriber", CompareGUIDFilter);

            }

そして、ランダムに生成された文字列は次のようになります。

public string GetRandomString(int length)
        {
            Random r = new Random();
            string result = "";
            for (int i = 0; i < length; i++)
            {
                result += allowedchars.Substring(r.Next(0,allowedchars.Length),1);
            }
            return result;
        }

問題は、messageId を "GUID" などの静的なものに設定すると、フィルターが適切に機能することですが、上記の関数を使用して生成すると機能しません。どんな助けでも大歓迎です。

4

1 に答える 1

0

sql フィルターに問題はありません。しかし、トピックはその id キー値でメッセージを永続化します。したがって、サブスクライバーを介して後のメッセージにアクセスすることはできません。

于 2013-05-06T13:31:55.967 に答える