Home:ALL Converter>Azure Service Bus - SQLFilter doesn't works as expected

Azure Service Bus - SQLFilter doesn't works as expected

Ask Time:2016-11-11T22:43:49         Author:sppc42

Json Formatter

Am trying to run the Azure Service Bus sample given in their official documentation at https://azure.microsoft.com/en-gb/documentation/articles/service-bus-dotnet-how-to-use-topics-subscriptions/.

Creating subscriptions

namespaceManager.CreateSubscription(TopicName, "CreatedMessages", new SqlFilter(@"Type = 'Created'"));

Sending Messages

public void SendMessages()
{
    var client = TopicClient.CreateFromConnectionString(_connectionString, TopicName);

    for (var i = 0; i < 5; i++)
    {
        var message = new BrokeredMessage("TestMessage " + i);

        if (i%2 == 0)
            message.Properties["Type"] = "Created";
        else
            message.Properties["Type"] = "All";

        client.Send(message);
    }
}

Handling Messages

    public void ListenMessages()
    {
        Task.Factory.StartNew(() => SubscribeMessages("CreatedMessages"));
    }

    public void SubscribeMessages(string subscription)
    {
        var allMessagesClient = SubscriptionClient.CreateFromConnectionString(_connectionString, TopicName, subscription);

        allMessagesClient.OnMessage(message =>
        {
            try
            {
                Console.WriteLine($"** {subscription} **");
                Console.WriteLine("Body: " + message.GetBody<string>());
                Console.WriteLine("MessageID: " + message.MessageId);
                Console.WriteLine("Message Type: " + message.Properties["Type"]);
                Console.WriteLine();

                message.Complete();
            }
            catch (Exception)
            {
                message.Abandon();
            }
        },
        new OnMessageOptions
        {
            AutoComplete = false,
            AutoRenewTimeout = TimeSpan.FromMinutes(1)
        });
    }

The above code works as expected.

However, problem am facing is that the moment the 'Type' property is renamed to anything else, like 'MessageType' or 'Name', the SQLFilter just stops working and i don't get any more messages.

What am I doing wrong?

Author:sppc42,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40550375/azure-service-bus-sqlfilter-doesnt-works-as-expected
yy