我正在为使用主题/订阅的云服务创建SQL过滤器。我为我的代理消息宣布了一个属性,看起来像这样
BrokeredMessage message = new BrokeredMessage("Response Message#"+ (++counter) +" Body");
// Set additional custom app-specific property
message.Properties["MsgGUID"] = RequestMessageID; //assign msgGUID read from the Azure Queue
// Send message to the topic
Client.Send(message);
想要实现的是当我向工作者角色发送消息时,消息将包含随机生成的字符串。 worker角色将该字符串视为我的ID并创建一个代理消息,其“MsgGUID”属性将保存该ID。我的SQL过滤器如下所示:
SqlFilter CompareGUIDFilter = new SqlFilter("MsgGUID = '" + messageID + "'");//Filter based on the Requested GUID i.e. msgGUID
if (!nameSpaceManager.SubscriptionExists("TestTopic", "RequestMessageGUIDSubscriber"))
{
/*Subscriber with Filter as Receive only those Messages from the Topic that are
requested by the controller from another RequestQueue(Azure Queue) with GUID as messageID*/
nameSpaceManager.CreateSubscription("TestTopic", "RequestMessageGUIDSubscriber", CompareGUIDFilter);
}
我随机生成的字符串如下所示:
public string GetRandomString(int length)
{
Random r = new Random();
string result = "";
for (int i = 0; i < length; i++)
{
result += allowedchars.Substring(r.Next(0,allowedchars.Length),1);
}
return result;
}
现在问题是当我将messageId设置为静态的东西,比如“GUID”时,过滤器正常工作,但是当我使用上面的函数生成它时,它不起作用。任何帮助将不胜感激。
答案 0 :(得分:0)
sql过滤器没有问题。但是主题使用该id键值将消息保留在其中。因此,您无法通过订阅者访问以后的消息。