azure - Azure ServiceBus 上的 SqlFilter 主题订阅未过滤

标签 azure servicebus

我有一个 WinRT 应用程序,正在使用适用于 Windows 8 的 Windows Azure Toolkit。我有一个设置,我希望订阅的客户端忽略发布到 ServiceBus 主题的消息(如果他们是发起者或者消息早于订阅开始时的消息)。

在我的 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!  :(
    }

我拿回了所有东西——所以我不确定我做错了什么。解决订阅过滤器问题的最简单方法是什么?

最佳答案

当您创建订阅时,默认情况下您会获得“MatchAll”过滤器。在上面的代码中,您只需添加过滤器,以便除了“MatchAll”过滤器之外还应用它,从而收到所有消息。创建订阅后,只需删除 $Default 过滤器即可解决问题。

关于azure - Azure ServiceBus 上的 SqlFilter 主题订阅未过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11639437/

相关文章:

azure - 在 Azure 应用服务设置中存储连接字符串

azure - Microsoft Azure Service Fabric SDK 和 Windows Azure 包 : Service Bus 1. 1

Azure 函数超时/无法完成

Azure 服务总线有序处理消息

asp.net-mvc - ApplicationUser - 我如何使用它?我需要在 using 子句中添加什么?

java - 使用 ClientID 、 TennantID 和 ClientSecret 从 Azure 下载时出现问题

Magento 2 : Error when listing customers or adding a new one

c# - Azure.Data.Tables通用基类问题

c# - 在 MVC 3 中实现 Windows Azure 服务总线主题/订阅?

python - Azure 服务总线队列发送和接收消息的测试