如何在Azure Service Bus中向主题的订阅添加筛选器 [英] How to add filters to Topic's subscription in Azure Service Bus

查看:53
本文介绍了如何在Azure Service Bus中向主题的订阅添加筛选器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为订阅添加过滤器,以便对不同类型的事件执行不同的操作.

i want add filter for subscription so that different actions are performed on different types of event.

如何向其中添加过滤器.在发送至主题之前是否应添加还是可以在azure门户网站中完成?

How do i add filters to it. Should it be added before sending to topic or it can be done in azure portal?

推荐答案

可以在Azure门户中为特定订阅添加筛选器,也可以在从编码端发送时添加添加筛选器.

Filters can be added in the Azure Portal for a particular subscription or it can be done added while sending from the coding side also.

在这里,我分享了可以从 Azure Portal

Here I am sharing the method where we can add a filter from Azure Portal

示例:在下面的代码中,我正在向名为"apptopic"的主题发送消息.

Example: In the below code I am sending a message to a topic named "apptopic"

for(int i=0;i<5;i++)
{
  Order obj = new Order();
  var _message = new Message(Encoding.UTF8.GetBytes(obj.ToString()));
  _message.MessageId = $"{i}";
  _message.UserProperties.Add("Category", Exams[i]);           
  await _client.SendAsync(_message);
  Console.WriteLine($"Sending Message : {obj.Id} ");
}

该主题已被三个订阅 SubscriptionA SubscriptionB SubscriptionC 订阅.

This topic has been subscribed by three subscriptions SubscriptionA, SubscriptionB, SubscriptionC.

因此,我想在 MessageId为1 时向SubscriptionC添加过滤器以接收消息.

So I want to add a filter to SubscriptionC to receive messages when MessageId is 1.

因此转到要添加过滤器的特定订阅.然后删除屏幕快照中突出显示的默认过滤器..

So go to a particular subscription which you want to want to add a filter. Then delete the default filter which is highlighted in the screenshot. .

然后点击添加过滤器",按照屏幕快照中的说明提供过滤器名称和过滤条件,并保存..

Then click on Add Filter, Give the filter name and Filter condition as mentioned in the screenshot and save the changes. .

在此流程订阅中,

  1. 订阅A将收到-5条消息
  2. 订阅B将收到-5条消息
  3. 订阅C将收到-1条消息(由于添加了过滤器)

这篇关于如何在Azure Service Bus中向主题的订阅添加筛选器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆