我正在为使用主题/订阅的云服务创建 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”时,过滤器可以正常工作,但是当我使用上述函数生成它时,它就不起作用了。任何帮助,将不胜感激。