Title: Create a topic with authorization rule using azure-messaging-servicebus
Tags: java;azure;groovy;azureservicebus
Question: I'm trying to create a topic using ServiceBusAdministrationClient connected through a namespace's root manage access key
(com.azure:azure-messaging-servicebus:7.8.0)
```def createOptions = new CreateTopicOptions()
def authRule = new SharedAccessAuthorizationRule(authRuleName, [AccessRights.SEND, AccessRights.LISTEN])
createOptions.authorizationRules.add(authRule)
def topicProps = administrationClient.createTopic(topicName, createOptions)
```
but there are no AuthorizationRules associated with the topic.
I did the same thing when creating a queue and it worked.
Any ideas what I might be missing?



Here is another answer: For the authorization rule, you need to use Azure Resource Management library
Below is a sample to create an authorization rule
```final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);

final TokenCredential credential =
    new DefaultAzureCredentialBuilder()
        .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
        .build();

var azureResourceManager =
    AzureResourceManager.configure()
        .withLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)
        .authenticate(credential, profile)
        .withSubscription(&quot;subscription&quot;);

ServiceBusManager manager = azureResourceManager.serviceBusNamespaces().manager();

SBAuthorizationRuleInner authorizationRule =
    manager
        .serviceClient()
        .getTopics()
        .createOrUpdateAuthorizationRule(
            &quot;resourceGroupName&quot;, &quot;namespaceName&quot;, &quot;topicName&quot;, &quot;authorizationRuleName&quot;);
```

Comment for this answer: Yes, in the end I used this library because I could not find why azure-messaging-servicebus is not working as I assumed. Maybe someone can still figure it out.
Comment for this answer: Agree, it's confusing. I think the Azure team should move all management-related stuff to the resource management library. BTW, if you had already figured it out then please post the answer, it would have helped others. I spent countless hours :-)

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:05/31/22', 'FavoriteCount': 0.0, 'PostTypeId': 1, 'Tags': '<java><azure><groovy><azureservicebus>', 'Title': 'Create a topic with authorization rule using azure-messaging-servicebus', 'ViewCount': 90, 'id': 72442325, 'user_AboutMe': None, 'user_AccountId': 23651652.0, 'user_DisplayName': 'GeumLiAh', 'user_Reputation': 11.0, 'user_Views': 10.0, 'user_id': 17680444.0}}