共用方式為


ServiceBusRuleManagerAsyncClient Class

  • java.lang.Object
    • com.azure.messaging.servicebus.ServiceBusRuleManagerAsyncClient

Implements

public class ServiceBusRuleManagerAsyncClient
implements AutoCloseable

An asynchronous rule manager responsible for managing rules for a specific topic subscription. The rule manager requires only Listen claims, whereas the ServiceBusAdministrationAsyncClient requires Manage claims.

Create an instance of rule manager

// 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();

Create a rule to a Service Bus subscription

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();

Fetch all rules.

// `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()));

Delete a rule.

// `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.")
 );

Method Summary

Modifier and Type Method and Description
void close()

Disposes of the ServiceBusRuleManagerAsyncClient.

Mono<Void> createRule(String ruleName, CreateRuleOptions options)

Creates a rule to the current subscription to filter the messages reaching from topic to the subscription.

Mono<Void> deleteRule(String ruleName)

Removes the rule on the subscription identified by ruleName.

String getEntityPath()

Gets the name of the Service Bus resource.

String getFullyQualifiedNamespace()

Gets the fully qualified namespace.

Flux<RuleProperties> listRules()

Fetches all rules associated with the topic and subscription.

Methods inherited from java.lang.Object

Method Details

close

public void close()

Disposes of the ServiceBusRuleManagerAsyncClient. If the client has a dedicated connection, the underlying connection is also closed.

createRule

public Mono createRule(String ruleName, CreateRuleOptions options)

Creates a rule to the current subscription to filter the messages reaching from topic to the subscription.

Parameters:

ruleName - Name of rule.
options - The options for the rule to add.

Returns:

A Mono that completes when the rule is created.

deleteRule

public Mono deleteRule(String ruleName)

Removes the rule on the subscription identified by ruleName.

Parameters:

ruleName - Name of rule to delete.

Returns:

A Mono that completes when the rule is deleted.

getEntityPath

public String getEntityPath()

Gets the name of the Service Bus resource.

Returns:

The name of the Service Bus resource.

getFullyQualifiedNamespace

public String getFullyQualifiedNamespace()

Gets the fully qualified namespace.

Returns:

The fully qualified namespace.

listRules

public Flux listRules()

Fetches all rules associated with the topic and subscription.

Returns:

A list of rules associated with the topic and subscription.

Applies to