我有一个WinRT应用程序,我正在使用Windows Azure Toolkit for Windows 8.我有一个设置,我希望客户订阅忽略发布到ServiceBus主题的消息,如果他们是发起者或者消息比他们的订阅开始时更早.
在我的BrokeredMessage的属性中,我添加了2个项目来涵盖这些场景:
message.Properties["Timestamp"] = DateTime.UtcNow.ToFileTime();
message.Properties["OriginatorId"] = clientId.ToString();
Run Code Online (Sandbox Code Playgroud)
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! :(
}
Run Code Online (Sandbox Code Playgroud)
我找回了所有东西 - 所以我不确定我做错了什么.解决订阅过滤器问题的最简单方法是什么?
Abh*_*Lal 13
创建订阅时,默认情况下会获得"MatchAll"过滤器.在上面的代码中,您只是添加了过滤器,因此除了"MatchAll"过滤器之外,还会应用它,因此会收到所有消息.只需在创建订阅后删除$ Default过滤器,即可解决问题.
| 归档时间: |
|
| 查看次数: |
3421 次 |
| 最近记录: |