你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
ServiceBusRuleManagerAsyncClient 类
- java.
lang. Object - com.
azure. messaging. servicebus. ServiceBusRuleManagerAsyncClient
- com.
实现
public class ServiceBusRuleManagerAsyncClient
implements AutoCloseable
负责管理特定主题订阅的规则 的异步 规则管理器。 规则管理器只需要侦听声明,而 ServiceBusAdministrationAsyncClient 需要管理声明。
创建规则管理器的实例
// The required parameters is connectionString, a way to authenticate with Service Bus using credentials.
// The connectionString/queueName must be set by the application. The 'connectionString' format is shown below.
// "Endpoint={fully-qualified-namespace};SharedAccessKeyName={policy-name};SharedAccessKey={key}"
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
// 'fullyQualifiedNamespace' will look similar to "{your-namespace}.servicebus.windows.net"
ServiceBusRuleManagerAsyncClient ruleManager = new ServiceBusClientBuilder()
.credential(fullyQualifiedNamespace, credential)
.ruleManager()
.topicName(topicName)
.subscriptionName(subscriptionName)
.buildAsyncClient();
为服务总线订阅创建规则
RuleFilter trueRuleFilter = new TrueRuleFilter();
CreateRuleOptions options = new CreateRuleOptions(trueRuleFilter);
// `subscribe` is a non-blocking call. After setting up the create rule operation, it will move onto the next
// line of code to execute.
// Consider using Mono.usingWhen to scope the creation, usage, and cleanup of the rule manager.
ruleManager.createRule("new-rule", options).subscribe(
unused -> {
},
err -> System.err.println("Error occurred when create a rule, err: " + err),
() -> System.out.println("Create complete.")
);
// Finally dispose of the rule manager when done using it.
ruleManager.close();
提取所有规则。
// `subscribe` is a non-blocking call. After setting up the list rules operation, it will move onto the next
// line of code to execute.
ruleManager.listRules().subscribe(ruleProperties -> System.out.println(ruleProperties.getName()));
删除规则。
// `subscribe` is a non-blocking call. After setting up the delete rule operation, it will move onto the next
// line of code to execute.
ruleManager.deleteRule("exist-rule").subscribe(
unused -> { },
err -> System.err.println("Error occurred when delete rule, err: " + err),
() -> System.out.println("Delete complete.")
);
方法摘要
修饰符和类型 | 方法和描述 |
---|---|
void | close() |
Mono<Void> |
createRule(String ruleName, CreateRuleOptions options)
为当前订阅创建一个规则,以筛选从主题到达订阅的消息。 |
Mono<Void> |
deleteRule(String ruleName)
删除 由 |
String |
getEntityPath()
获取服务总线资源的名称。 |
String |
getFullyQualifiedNamespace()
获取完全限定的命名空间。 |
Flux<Rule |
listRules()
提取与主题和订阅关联的所有规则。 |
方法继承自 java.lang.Object
方法详细信息
close
public void close()
释放 ServiceBusRuleManagerAsyncClient。 如果客户端具有专用连接,则基础连接也会关闭。
createRule
public Mono
为当前订阅创建一个规则,以筛选从主题到达订阅的消息。
Parameters:
Returns:
deleteRule
public Mono
删除 由 ruleName
标识的订阅上的规则。
Parameters:
Returns:
getEntityPath
public String getEntityPath()
获取服务总线资源的名称。
Returns:
getFullyQualifiedNamespace
public String getFullyQualifiedNamespace()
获取完全限定的命名空间。
Returns:
listRules
public Flux
提取与主题和订阅关联的所有规则。
Returns: