![](/img/trans.png)
[英]how to send a message to azure service bus Topic (subscription using) Logic app send message connector?
[英]How to send a message to only one Azure Service Bus Subscription?
我应该使用主题和过滤器吗? 不确定是否是更好的做法。
是的。 这是主题和订阅的经典用例。
如果是,是否存在将消息发送到正确订阅的方法? 例如,我向订阅 X 发布一条消息,而不是为所有订阅发布。
发布的工作方式是将其发布到主题,主题获取消息并针对所有订阅的过滤器进行验证。 具有满足过滤条件的订阅会收到该消息。 不满足过滤条件的订阅将被跳过。 滤波器共有三种类型,Boolean、SQL 和 Correlation。 Boolean 过滤器与您不太相关。 相关或 SQL 过滤器将完成这项工作。 您可以在我的帖子中找到有关过滤器的更多信息。
我在这里建议的是用通知的方法“标记”每条消息。 由于您将为每个方法使用一个通知方法,因此 Correlation 过滤器将是最简单和最有效的。 通知方法值可以分配给传出消息的Label
系统属性和两个订阅的相关过滤器(一个用于 email 服务,一个用于推送通知服务)。 例如(伪代码):
var message = new Message();
// custom logic to determine what notification method to use
if (notificationMethod == NotificationMethod.Email)
{
message.Label = "email";
}
else
{
message.Label = "push";
}
// publish the message to the topic
两个过滤器设置将是:
// email notification service subscription
var emailFilter = new CorrelationFilter();
filter.Label = "email";
// push notifications service subscription
var pushFilter = new new CorrelationFilter();
filter.Label = "push";
使用给定过滤器创建订阅(例如电子邮件):
var management = new ManagementClient(...);
await management.CreateSubscriptionAsync(new SubscriptionDescription("topic", "subscription"));
var client = new SubscriptionClient("topic", "subscription");
await client.AddRuleAsync(new RuleDescription(
{
Filter = emailFilter,
Name = "email filter"
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.