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?