joecop
joecop

Reputation: 13

SqlFilter on Azure ServiceBus Topic subscription not filtering

I’ve got a WinRT app that I’m using the Windows Azure Toolkit for Windows 8 with. I’ve got a setup where I’d like clients subscribed to ignore messages posted to a ServiceBus Topic if they’re the originator or if the message is older than when their subscription started.

In the Properties of my BrokeredMessage, I’ve added 2 items to cover these scenarios:

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

clientId is a Guid.

The subscriber side looks like this:

// 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!  :(
    }

I get back everything – so I’m not sure what I’m doing wrong. What’s the easiest way to troubleshoot problems with subscription filters?

Upvotes: 1

Views: 4573

Answers (2)

Abhishek Lal
Abhishek Lal

Reputation: 3231

When you create a Subscription then by default you get a "MatchAll" filter. In the code above you are just adding your filter so it is applied in addition to the "MatchAll" filter and thus all messages are recieved. Just delete the $Default filter once the Subscription is created and that should resolve the issue.

Upvotes: 14

user728584
user728584

Reputation: 2135

Best way to troubleshoot is using the Service Bus Explorer from Paolo Salvatori http://code.msdn.microsoft.com/windowsazure/Service-Bus-Explorer-f2abca5a

He has done a good few blog posts on it e.g. http://windowsazurecat.com/2011/07/exploring-topics-and-queues-by-building-a-service-bus-explorer-toolpart-1/

Windows Azure SDK 1.7 does have built in capability but the Service Bus Explorer Standalone version is still better, see comparison here.

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

HTH your debugging...

Upvotes: 1

Related Questions