将消息发送到具有大众运输的天蓝色服务总线主题中的特定订户组

问题描述 投票:0回答:1

我是天青服务公交车和大众运输的新手。我正在寻找针对特定情况的解决方案。

我有一个具有多个订户的天蓝色服务总线主题。订户将接收基于过滤器的消息。我使用下面的代码创建了主题和订阅者]

class Program
    {
        static void Main(string[] args)
        {

            string connectionString = "Endpoint connection string";

            // the names of topics and subscriptions we'll be working with
            const string topicName = "MyTestTopic";
            const string allMessagesSubName = "AllMessages";
            const string filteredSubName1 = "Filtered1";
            const string filteredSubName2 = "Filtered2";

            // let's create the topic if it doesn't already exist...
            var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
            if (!namespaceManager.TopicExists(topicName))
            {
                var td = new TopicDescription(topicName);
                namespaceManager.CreateTopic(td.Path);
            }
            if (!namespaceManager.SubscriptionExists(topicName, allMessagesSubName))
            {
                namespaceManager.CreateSubscription(topicName, allMessagesSubName);
            }

            if (!namespaceManager.SubscriptionExists(topicName, filteredSubName1))
            {
                namespaceManager.CreateSubscription(
                    new SubscriptionDescription(topicName, filteredSubName1),
                    new Microsoft.ServiceBus.Messaging.SqlFilter("From LIKE '%Smith'"));
            }

            if (!namespaceManager.SubscriptionExists(topicName, filteredSubName2))
            {
                namespaceManager.CreateSubscription(
                    new SubscriptionDescription(topicName, filteredSubName2),
                    new Microsoft.ServiceBus.Messaging.SqlFilter("sys.Label='important'"));
            }

            var message1 = new BrokeredMessage("Hello World");

            var message2 = new BrokeredMessage("Second message");
            message2.Label = "important";

            var message3 = new BrokeredMessage("Third message");
            message3.Properties["From"] = "Kelly Smith";
            message3.Label = "information";

            var client = TopicClient.CreateFromConnectionString(connectionString, topicName);
            client.Send(message1);
            client.Send(message2);
            client.Send(message3);
            client.Close();
        }
    }

在这里,我们在代码中添加消息自定义属性

,例如发件人>>。

现在我想使用masstransit发送此类消息。在masstransit中,我找不到使用Publish()

方法添加消息自定义属性的任何选项。有什么方法可以在可以使用这些过滤器的地方使用masstransit发送这些消息?

NB:我已经阅读了此question的答案,但是这里的答案告诉我们在订户端过滤消息。我想要的是,此过滤将在到达订阅者之前进行。

我是天青服务公交车和大众运输的新手。我正在寻找针对特定情况的解决方案。我有一个具有多个订户的azure服务总线主题。订户将基于以下内容接收消息:

azure azureservicebus masstransit azure-servicebus-topics azure-servicebus-subscriptions
1个回答
0
投票

将Azure Service Bus与MassTransit一起使用时,可以在常规终结点之外添加订阅终结点

。在配置订阅端点时,您应该能够指定规则和/或过滤器作为订阅的一部分。这正是您在上面所做的,因此可以解决。
© www.soinside.com 2019 - 2024. All rights reserved.