0

我有一个名为“AZTopic”的 Azure 主题,并且我有一个添加了三个规则描述的订阅。规则描述具有基于属性优先级的 sql 过滤器。当我尝试从订阅访问数据时,我得到 null 作为代理消息。

private static void CreateSubscription(string filterName, string subscriptionName)
    {            
        if (!namespaceManager.SubscriptionExists(Constants.Topic, subscriptionName))
        {
           namespaceManager.CreateSubscription(Constants.Topic, subscriptionName);                
        }
        SubscriptionClient subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, Constants.Topic, subscriptionName);

        var rules = namespaceManager.GetRules(Constants.Topic,Constants.P0Subscription);
        foreach (var rule in rules)
        {
            subscriptionClient.RemoveRule(rule.Name);
        }

        var P0FilterRule = new RuleDescription()
        {
            Filter = new SqlFilter(Constants.P0Filter),
            Name = "P0"
        };
        var P1FilterRule = new RuleDescription()
        {
            Filter = new SqlFilter(Constants.P1Filter),
            Name = "P1"
        };
        var P2FilterRule = new RuleDescription()
        {
            Filter = new SqlFilter(Constants.P2Filter),
            Name = "P2"
        };

        subscriptionClient.AddRule(P0FilterRule);
        subscriptionClient.AddRule(P1FilterRule);
        subscriptionClient.AddRule(P2FilterRule);           
    }

这是我的订阅创建代码

private QueueMessage GetMessage(string filterName, string subscriptionName)
    {
        BrokeredMessage receivedMessage = new BrokeredMessage();
        QueueMessage messageObject = new QueueMessage();
        SubscriptionClient Client = SubscriptionClient.CreateFromConnectionString(Settings.connectionString, Constants.Topic, subscriptionName);
        try
        {
            receivedMessage = Client.Receive();
            if (receivedMessage != null)
            {
                messageObject = receivedMessage.GetBody<QueueMessage>();
                receivedMessage.Complete();
            }
        }
        catch (Exception ex)
        {
            Logger.Log(ex.GetBaseException().Message, LogLevel.Informational, "");
            receivedMessage.Abandon();
        }

        return messageObject;
    }

这是我的消息阅读代码

4

0 回答 0