2012-07-24 84 views
1

我有一個WinRT應用程序,我正在使用Windows Azure Toolkit for Windows 8。我有一個設置,我希望客戶訂閱忽略發佈到ServiceBus主題的消息,如果他們是發件人或者消息比訂閱開始時更早。Azure ServiceBus上的SqlFilter主題訂閱沒有過濾

在我BrokeredMessage的屬性,我已經添加了2項涵蓋了這些情況:

message.Properties["Timestamp"] = DateTime.UtcNow.ToFileTime(); 
message.Properties["OriginatorId"] = clientId.ToString(); 

的clientId是一個GUID。

用戶側看起來是這樣的:

// ti is a class that contains a Topic, Subscription and a bool as a cancel flag. 

string FilterName = "NotMineNewOnly"; 

// Find or create the topic. 
if (await Topic.ExistsAsync(DocumentId.ToString(), TokenProvider)) 
{ 
    ti.Topic = await Topic.GetAsync(DocumentId.ToString(), TokenProvider); 
} 
else 
{ 
    ti.Topic = await Topic.CreateAsync(DocumentId.ToString(), TokenProvider); 
} 

// Find or create this client's subscription to the board. 
if (await ti.Topic.Subscriptions.ExistsAsync(ClientSettings.Id.ToString())) 
{ 
    ti.Subscription = await ti.Topic.Subscriptions.GetAsync(ClientSettings.Id.ToString()); 
} 
else 
{ 
    ti.Subscription = await ti.Topic.Subscriptions.AddAsync(ClientSettings.Id.ToString()); 
} 

// Find or create the subscription filter. 
if (!await ti.Subscription.Rules.ExistsAsync(FilterName)) 
{ 
    // Want to ignore messages generated by this client and ignore any that are older than Timestamp. 
    await ti.Subscription.Rules.AddAsync(FilterName, sqlFilterExpression: string.Format("(OriginatorId != '{0}') AND (Timestamp > {1})", ClientSettings.Id, DateTime.UtcNow.ToFileTime())); 
} 

ti.CancelFlag = false; 

Topics[boardId] = ti; 

while (!ti.CancelFlag) 
{ 
    BrokeredMessage message = await ti.Subscription.ReceiveAndDeleteAsync(TimeSpan.FromSeconds(30)); 

    if (!ti.CancelFlag && message != null) 
    { 
     // Everything gets here! :(
    } 

我回來的一切 - 所以我不知道我做錯了。解決訂閱過濾器問題的最簡單方法是什麼?

回答

10

當您創建訂閱則默認情況下你會得到一個 「MatchAll」 過濾器。在上面的代碼中,您只需添加過濾器,以便在「MatchAll」過濾器之外應用它,從而接收所有消息。創建訂閱後,只需刪除$ Default過濾器即可解決問題。

+0

是的,這是問題所在。我剛剛發現我自己使用服務總線瀏覽器。謝謝! – joecop 2012-07-26 02:24:17

0

從保羅撒瓦特瑞使用服務總線資源管理器來解決的最佳方式 http://code.msdn.microsoft.com/windowsazure/Service-Bus-Explorer-f2abca5a

他已經做了好幾個博客文章就可以瞭如http://windowsazurecat.com/2011/07/exploring-topics-and-queues-by-building-a-service-bus-explorer-toolpart-1/

Windows Azure SDK 1.7具有內置功能,但Service Bus Explorer Standalone版本仍然更好,請參閱此處的比較。

http://soa-thoughts.blogspot.com.au/2012/06/visual-studio-service-bus-explorer.html

HTH您的調試......

+0

感謝您的提示。找到導致問題的$默認規則。 – joecop 2012-07-26 02:25:27