我正在为使用主题/订阅的云服务创建 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);
想要实现的是,当我向我的辅助角色发送消息时,该消息将包含一个随机生成的字符串。辅助角色会将该字符串视为我的 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”)时,过滤器可以正常工作,但是当我使用上述函数生成它时,它不起作用。任何帮助将不胜感激。
最佳答案
sql过滤器没有问题。但主题会使用该 id 键值将消息保留在其中。因此您无法通过您的订阅者访问后续消息。
关于azure - Windows Azure 中的 SQL 筛选器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16332753/